SPSS Recode

The RECODE command replaces values of a variable.


Usage

Numeric Variables

1 or more variables can be specified on a RECODE command. They must all be numeric variables.

recode foo bar baz (0=sysmis).

Ranges are valid on the left side of an instruction. They are inclusive and capture non-integers.

recode foo (0 thru 10=1).

The LO/LOWEST and HI/HIGHEST keywords dynamically capture the lowest and highest non-missing values. These keywords are only valid on ranges.

The SYSMIS keyword captures system missing values, while the MISSING keyword captures both user missing and system missing values. Both are valid on the left side of an instruction; only SYSMIS is a valid right side value.

The ELSE keyword captures all cases.

If destination variables are specified...

The COPY instruction causes matching cases to have be returned their pre-existing value. This is generally only useful with destination variables.

recode foo (0=sysmis) into bar.
recode foo (0=sysmis) (else=copy) into bar.

String Variables

1 or more variables can be specified on a RECODE command. They must all be string variables.

recode foo bar baz ("."="").

If any pattern is longer than all source variables, it is implicitly truncated to that length.

Spaces are implicitly trimmed from values when checking against patterns.

The MISSING keyword captures user missing values. It is only valid on the left side of an instruction.

The ELSE keyword captures all cases.

If destination variables are specified...

The COPY instruction causes matching cases to have be returned their pre-existing value. This is generally only useful with destination variables.

recode foo (0=sysmis) into bar.
recode foo (0=sysmis) (else=copy) into bar.


String Variables

Values are compared to recode instructions with an implicit rtrim call (i.e. trailing whitespace is not compared).

SPSS will also emit a warning if a recode instruction includes a value that is too long to possibly be found within the variable.


Type Conversion

To convert a numeric variable into a string, try:

recode numeric_zip_code (0="NULL") (sysmis="") (convert) into string_zip_code.

Note that specific values can be handled differently by including a recode instruction ahead of the convert instruction.

To convert a string variable into a number, try:

recode string_zip_code ("NULL"=0) (""=sysmis) (convert) into numeric_zip_code.

Note that non-numeric values (including blank values) must be handled explicitly by including a recode instruction ahead of the convert instruction, or they will all be replaced with the system missing value and a warning will be emitted.


CategoryRicottone