How to convert numeric to string in SPSS

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

Go to File > New > Syntax . In SPSS Syntax Editor, paste the following syntax :

Code            Code1
23464.25     23464.25
2134.27       2134.27
.00               0
Number of cases read:  3    Number of cases listed:  3

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 with width 12
3. The BEGIN DATA and END DATA commands enclose the raw data.
4. STRING(numeric type variable, format) returns the value of the numeric expression as a string. For example, STRING(23464.25, F10.2) returns the string value '23464.25'. F10.2 indicates numeric variable with width 10 and 2 decimals. 
5. SUBSTR(string variable, position, [number of characters]) returns the substring beginning at character position of string variable.The third parameter is optional. For example SUBSTR('23464.25', 1,4) returns '2346'
6. RINDEX(within_text, find_text, [number of characters used to divide find_text into separate strings]) returns a number that indicates the starting character position of the last occurence of the find text. For example, RINDEX('23464.25', "123456789",1) returns 10
7. LTRIM removes leading spaces.

String conversion into the same variable
Add the following lines of code after EXECUTE statement.

ListenData Logo
Spread the Word!
Related Posts
About Author:
Deepanshu Bhalla

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

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

Post a Comment

Next → ← Prev
Looks like you are using an ad blocker!

To continue reading you need to turnoff adblocker and refresh the page. We rely on advertising to help fund our site. Please whitelist us if you enjoy our content.