Suppose you have a string variable type data and you wish to convert it to numeric.
Example
Result
code numcode
12348 12348.00
12457 12457.00
Number of cases read: 2 Number of cases listed: 2
Explanation
1. DATA LIST defines a raw data file . The keyword FREE indicates multiple cases can be entered on a single row (freefield format).
Go to File > New > Syntax . In SPSS Syntax Editor, paste the following syntax :
Result
code numcode
12348 12348.00
12457 12457.00
Number of cases read: 2 Number of cases listed: 2
Explanation
1. DATA LIST defines a raw data file . The keyword FREE indicates multiple cases can be entered on a single row (freefield format).
2. Variable definition begins after the slash. Code is the variable name and A12 indicates string variable type with width 12
3.The BEGIN DATA and END DATA commands enclose the raw data.
4. With RECODE, you can change the values of an existing variable.
5. With CONVERT keyword, you can convert a variable type from string to numeric.
6. With INTO keyword, you can recode values of a variable into a new variable
Numeric conversion into the same variable
RECODE code (CONVERT) INTO numcode.
EXECUTE .
DELETE VARIABLES code.
RENAME VARIABLES (numcode = code).
LIST .
3.The BEGIN DATA and END DATA commands enclose the raw data.
4. With RECODE, you can change the values of an existing variable.
5. With CONVERT keyword, you can convert a variable type from string to numeric.
6. With INTO keyword, you can recode values of a variable into a new variable
Numeric conversion into the same variable
RECODE code (CONVERT) INTO numcode.
EXECUTE .
DELETE VARIABLES code.
RENAME VARIABLES (numcode = code).
LIST .
Share Share Tweet