String Variables (RECODE command)
- Target variables must already exist. To create a
new string variable, declare the variable with the
STRING
command before specifying it onRECODE
. - The new string values cannot be longer than the defined width of the target variable.
- If the new values are shorter than the defined width of the target variable, the values are right-padded with blanks.
- Multiple target variables are allowed. The target variables must all be the same defined width; the source variables can have different widths.
- If the source and target variables have different widths, the criterion for the width of the original values is the width defined for the source variable; the criterion for the width of the recoded values is the width defined for the target variable.
Using Keyword COPY With Target Variables
STRING STATE1 (A2).
RECODE STATE ('IO'='IA') (ELSE=COPY) INTO STATE1.
-
STRING
declares the variable STATE1 so that it can be used as a target variable onRECODE
. -
RECODE
specifies STATE as the source variable and STATE1 as the target variable. The original value IO is recoded to IA. The keywordsELSE
andCOPY
copy all other state codes over unchanged. Thus, STATE and STATE1 are identical except for cases with the original value IO.
Recoding a String Variable Into a Numeric Target
RECODE SEX ('M'=1) ('F'=2) INTO NSEX.
-
RECODE
recodes the string variable SEX into the numeric variable NSEX. Any value other than M or F becomes system-missing. - The program can process a large number of cases more efficiently with the numeric variable NSEX than it can with the string variable SEX.