Example 1 (variable data): Recode to reverse a scale
RECODE Q2A (1=5,2=4,4=2,5=1)
means, ‘For variable Q2A, recode the value 1 to 5, the value 2 to 4, the value 4 to 2 and the value 5 to 1.’
Example 2 (ASCII data): Recode to reverse a scale
RECODE 1/3 (1=5,2=4,4=2,5=1)
means, ‘For record 1, column 3, recode the value 1 to 5, the value 2 to 4, the value 4 to 2 and the value 5 to 1.’
Example 3 (variable data): Recode values
RECODE Q6 (55=99,66=99)
means, ‘For variable Q6, recode value 55 to 99 and recode value 66 to 99.’
Example 4 (ASCII data): Recode values
RECODE 1/20:2 (55=99,66=99)
means, ‘For record 1, starting in column 20, 2-column fields, recode value 55 to 99 and recode value 66 to 99.’
Example 5 (variable data): Recode variable string characters to numeric values
RECODE PRODUCT (A=1,B=2,C=3)
means, ‘For variable PRODUCT, recode value A to 1, value B to 2 and value C to 3.’
Example 6 (ASCII data): Recode ASCII string characters to numeric values
RECODE 2/43 (A=1,B=2,C=3)
means, ‘For record 2, column 43, recode value A to 1, value B to 2 and value C to 3.’
Example 7 (variable data): Using IF logic
IF Q1 ( ) RECODE INCOME ( =5)
means, ‘If variable Q1 is blank, recode variable INCOME to value 5.’
Example 8 (ASCII data): Using IF logic
IF 3/34 ( ) RECODE 3/35 ( =5)
means, ‘If record 3, column 34 is blank, recode record 3, column 35 to value 5.’
Example 9 (ASCII data): Recoding a single- column field to a multi-column field:
You need two statements to recode a value from a single-column field to a multi-column field. First, you assign a new two-column location with the ASSIGN command (fully described later in this section). Then you can write the RECODE statement. For example, if you want to recode a value of 0 from a single-column field to a value of 10, you must create a new 2-column field. This means you also need to assign the original location to a new location. For example:
ASSIGN 2/10:2 = 1/10 (Note: Using ASSIGN, the new location is written on the left of the equal sign.)
means, ‘Assign record 1, column 10, to record 2, columns 10 and 11 (2-column field).’
Then you can recode the old value to the new value:
RECODE 2/10:2 (0=10)
means, ‘For record 2, column 10 and 11, recode value 0 to value 10.’
You can use RECODE with indexed variables.