Examples (RECODE command)
Recoding Numeric Variables
RECODE V1 TO V3 (0=1) (1=0) (2,3=-1) (9=9) (ELSE=SYSMIS) /QVAR(1 THRU 5=1)(6 THRU 10=2)(11 THRU HI=3)(ELSE=0).
- The numeric variables between and including V1 and V3 are recoded: original values 0 and 1 are switched respectively to 1 and 0; 2 and 3 are changed to −1; 9 remains 9; and any other value is changed to the system-missing value.
- Variable QVAR is also recoded: original values 1 through 5 are changed to 1; 6 through 10 are changed to 2; 11 through the highest value in the data are changed to 3; and any other value, including system-missing, is changed to 0.
Recoding String Variables
RECODE STRNGVAR ('A','B','C'='A')('D','E','F'='B')(ELSE=' '). RECODE PET ('IGUANA', 'SNAKE ' = 'WILD ').
- Values A, B, and C are changed to value A. Values D, E, and F are changed to value B. All other values are changed to a blank.
- Values IGUANA and SNAKE are changed to value WILD. The defined width of the variable PET is 6. Thus, values SNAKE and WILD include trailing blanks for a total of six characters. If blanks are not specified, the values are right-padded. In this example, the results will be the same.
- Each string value is enclosed within quotes.