= 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... * any non-existant variables are initialized with missing values for all cases. * the source variables are not modified. * the number of source variables must match the number of destination variables. * values are only overwritten when a case matches an instruction based on the value of the source variable. 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 ("NULL"=""). }}} If any string literal on the left side of an instruction is longer than all source variables, it is implicitly truncated to that length. Spaces are implicitly trimmed from values when checking against left sides. A string literal on the right side of an instruction cannot be longer than any source variables. 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... * they must all be existing string variables. * the source variables are not modified. * the number of source variables must match the number of destination variables. * values are only overwritten when a case matches an instruction based on the value of the source variable. The `COPY` instruction causes matching cases to have be returned their pre-existing value. This is generally only useful with destination variables. {{{ recode foo ("NULL"="") into bar. recode foo ("NULL"="") (else=copy) into bar. }}} The `CONVERT` instructions causes strings representing numeric literals to be converted into actual numeric values. {{{ recode foo ("NULL"=sysmis) (convert) into bar. }}} ---- == Data Model == The `RECODE` command is queued as a pending transformation. ---- == See also == [[https://www.gnu.org/software/pspp/manual/html_node/RECODE.html|PSPP manual for RECODE]] ---- CategoryRicottone