How to convert string to numeric in SPSS

Suppose you have a string variable type data and you wish to convert it to numeric.

Example
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 keywordyou 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 .

Related Posts
About Author:

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 8 years of experience in data science. During his tenure, he has worked with global clients in various domains like Banking, Insurance, Telecom and Human Resource.

0 Response to "How to convert string to numeric in SPSS"

Post a Comment

Next → ← Prev
Love this Post? Spread the Word!
Share