Example 1 (Variable data): Assigning a value to an existing variable
ASSIGN GENDER = (1)
or
GENDER = (1)
means, ‘Put value 1 into the variable GENDER; replace the original value.’
Example 1A (ASCII data): Assigning a value to an existing location
ASSIGN 1/30:2 = (22)
or
1/30:2 = (22)
means, ‘Put value 22 into columns 30 and 31 of record 1; replace the original value.’
Example 2 (Variable data): ‘Blanking’ a variable
ASSIGN Q1 = ( )
or
Q1 = ( )
means, ‘Put blanks into the variable Q1.’
Example 2A (ASCII data): ‘Blanking’ a field
ASSIGN 2/45:5 = ( )
or
2/45:5 ( )
means, ‘Put blanks into columns 45 through 49 (5-column field) of record 2.’
Example 3 (Variable data): Copying from one variable to another variable
ASSIGN Q1 = Q8
or
Q1 = Q8
means, ‘Put the contents of variable Q8 into variable Q1.’
Example 3A (ASCII data): Copying from one location to another
ASSIGN 4/32 = 3/32
or
4/32 = 3/32
means, ‘Put the contents of record 3, column 32, into record 4, column 32.’
Example 4 (Variable data): Using IF logic:
IF GENDER (1) AND Q1 S3 (1) ASSIGN Q10 = ( )
means, ‘If there is value 1 in the variable GENDER and value 1 in variables Q1, Q2 or Q3 (the S scans three variables of equal length), put a blank in the variable Q10.’
Example 4A (ASCII data): Using IF logic (the ASSIGN keyword is required):
IF 1/35 (1) AND 2/5 S3 (1) ASSIGN 3/35 = ( )
means, ‘If there is value 1 in record 1, column 35 and value 1 in record 2, columns 5, 6, or 7 (the S scans three columns), put a blank in record 3, column 35.’
Example 5 (Variable data): Compare two variables as condition for ASSIGN:
IF Q1 < Q2 ASSIGN INCOME = (7)
means, ‘If the code value in variable Q1 is less than the code value in variable Q2, move a code 7 to variable INCOME.’
Example 5A (ASCII data): Compare two fields as condition for ASSIGN:
IF 1/34:2 < 1/44:2 ASSIGN 1/78 = (7)
means, ‘If the code value in record 1, columns 34 and 35 is less than the code value in record 1, columns 44 and 45, move a code 7 to record 1 column 78.’
Example 6: Recoding a single-position field to a multi-position field:
You need two statements to recode a value from a single-position field to a multi-position field. First, you assign a new two-position location using the ASSIGN command. Then you write a RECODE statement. For example, if you want to recode a value of 0 from a single-position field to a value of 10, you must create a new two-position field. Therefore, you assign the original location to a new location.
For example:
ASSIGN 2/10:2 = 1/10
or
2/10:2 = 1/10
means, “assign record 1, position 10 to record 2, positions 10 and 11 (two-position field).” Then, you can recode the old value to the new value.
For example:
RECODE 2/10:2 (0=10)
means, “for record 2, position 10 and 11, recode value 0 to value 10.” (Note that in RECODE, the old value is on the left of the equal sign.)
Alternatively, the following statement is another way of accomplishing the same result using only one instruction:
IF 1/10 (0) ASSIGN 2/10:2 = (10)
You can use ASSIGN with indexed variables.
Related topics: