johnfulwider.com | polisci


Convert string variables to numeric using SPSS syntax

Written by johnfulwider on February 18th, 2007

I like to do everything in SPSS syntax so my entire analysis is replicable from data entry to statistical operations. After strapping on my hip waders and stepping ever so gingerly into the muck that is the SPSS “help” files, I finally figured out how to convert string variables to numeric when, as it is wont to do, SPSS imports some Excel fields as strings and some as numeric, with no obvious reason why.

The command is:

RECODE oldvar (CONVERT) INTO newvar .

Note that “newvar” has to be just that; you have to use a new variable name. Otherwise, you get this error:

>Error # 4686 in column 28. Text: hccc
>On the RECODE command, an attempt has been made to assign a numeric value
>to a string variable which is named after the keyword INTO.
>This command not executed.

If you’re really fond of your original variable names, you could drop those variables and then do this:

RECODE newvar (ELSE=COPY) INTO oldvar.

Leave a Reply