Size: 3616
Comment:
|
← Revision 4 as of 2023-06-11 21:05:47 ⇥
Size: 3130
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 56: | Line 56: |
recode foo bar baz ("."=""). | recode foo bar baz ("NULL"=""). |
Line 59: | Line 59: |
If any pattern is longer than all source variables, it is implicitly truncated to that length. | 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. |
Line 61: | Line 61: |
Spaces are implicitly trimmed from values when checking against patterns. | A string literal on the right side of an instruction cannot be longer than any source variables. |
Line 77: | Line 77: |
recode foo (0=sysmis) into bar. recode foo (0=sysmis) (else=copy) into bar. |
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. |
Line 85: | Line 91: |
== Data Model == | |
Line 86: | Line 93: |
== 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. |
The `RECODE` command is queued as a pending transformation. |
Line 108: | Line 99: |
== Type Conversion == | == See also == |
Line 110: | Line 101: |
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. |
[[https://www.gnu.org/software/pspp/manual/html_node/RECODE.html|PSPP manual for RECODE]] |
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.