RECODE Examples

 

Example 1: Recode to reverse a scale

RECODE 1/3 (1=5,2=4,4=2,5=1)

means, ‘For card 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 2: 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 3: Recode values

RECODE 1/20:2 (55=99,66=99)

means, ‘For card 1, starting in column 20, 2-column fields, recode value 55 to 99 and recode value 66 to 99.’

 

Example 4: Recode values

RECODE Q6 (55=99,66=99)

means, ‘For variable Q6, recode value 55 to 99 and recode value 66 to 99.’

 

Example 5: Recode ASCII string characters to numeric values

RECODE 2/43 (A=1,B=2,C=3)

means, ‘For card 2, column 43, recode value A to 1, value B to 2 and value C to 3.’

 

Example 6: Recode ASCII 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 7: Using IF logic

IF 3/34 ( ) RECODE 3/35 ( =5)

means, ‘If card 3, column 34 is blank, recode card 3, column 35 to value 5.’

 

Example 8: Using IF logic

IF Q1 ( ) RECODE INCOME ( =5)

means, ‘If variable Q1 is blank, recode variable INCOME to value 5.’

 

Example 9: 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

 

means, ‘Assign card 1, column 10, to card 2, columns 10 and 11 (2-column field).’

(Note: Using ASSIGN, the new location is written on the left of the equal sign.)

Then you can recode the old value to the new value:

 

  RECODE 2/10:2 (0=10)

 

means, ‘For card 2, column 10 and 11, recode value 0 to value 10.’

 

You can use RECODE with indexed variables.