
I wrote the below macro which will parse out up to 25 columns. Thankfully it isn’t nearly as common now, but it does still occur.

I used to run into this problem very frequently. We really want to have each value in its own column and remove all delimiters. Occasionally we’ll get data which has multiple responses within one column or field. Sometimes we get data in “interesting” formats. Parsing Multiple Values Out to Their Own Columns in SPSS Want to drop the old numeric variable from the data set? Simply use the match files command with the drop statement.ĮXE. You’ll want to trim the original values first if you have more than five characters. Also note, because the last value was more than five characters, the conversion did not work.
#Spss code examples zip
In the example I showed above where we converted the numeric zip code back to a string, we padded the left side of the number with up to five zeros. But if you’re going to join your data with external sources, you should first examine the zip code there and see what format it is in. Depending on what we plan to do with the data, this situation may be irrelevant. In 99 percent of cases this is what we want however, the North East has zip codes that begin with zeros. The below screenshot shows an example of what the three variables could look like.Ī couple of things to point out from above, when you convert a string value to a numeric, for obvious reasons any leading zeros will no longer be kept. Now that you’ve created the variable, you can convert the numeric value to its string counterpart.ĬOMPUTE String_zip2=STRING(Numeric_zip,N5). The following creates a string variable named String_Zip2 with a width of five characters: If you need to convert a numeric value to a string there is one additional step: you must first declare the string variable. Numeric Variables to String Variables with SPSS Now you’ll see the Numeric_Zip variable is set to be Nominal:Īs a reference, below are the other variable levels supported in SPSS This can be achieved with the following line of syntax: To help remind yourself not to take the “average” of zip code you might want to change the variable level to Nominal. This gets us what we want however, as can be seen in the screenshot below, the new “Numeric_Zip” variable is currently set as a “Scale” variable.

RECODE String_Zip (Convert) INTO Numeric_zip.

Let’s say you wish to convert the variable named “String_Zip” to a numeric variable entitled “Numeric_zip.” The following is the SPSS syntax that would create the new variable: As long as the values are numbers with spaces on either side, this is very easy to accomplish. While Alchemer allows for changing of variable format inside the tool, occasionally I end up with string variables that really want to be numeric.
#Spss code examples how to
In this article Joe Glines, an SPSS pro with years of experience in data analysis, offers his quick tricks on how to manipulate the SPSS data we receive from Alchemer String Variables to Numeric with SPSS It is, however, an intricate process that demands a high level of expertise. With its emphasis on analyzing statistical data, SPSS is a powerful tool for manipulating survey data.
