SPSS Syntax 101: Basic Guidelines, Variable and Value Labels

Perhaps you’re now convinced that using SPSS syntax might save you some time in the long run. Maybe you even now know how to create a new syntax file. So what do you do with that file and how do you make it manage or analyze your data?

As a reminder, this forum focuses on common analyses performed by researchers and practitioners within organizational behavior, industrial/organizational psychology, and human resource management. An in-depth explanation of everything SPSS syntax can possibly do is far beyond this forum’s scope. The focus here is on practical issues and no-nonsense knowhow to bolster your productivity.

To begin, let’s cover a few guidelines regarding the use of SPSS syntax.

  • Notes: You can make notes to yourself within the syntax file about what you are analyzing, why you are analyzing it, what results you found, and anything else that may help put your analysis in context for future reference. To make a note to yourself, simply precede your note with an asterisk (*) and end your sentence with a period. That will ensure that SPSS will skip over that sentence when running the analysis you specify. It is sometimes useful to use many asterisks in a row to demarcate different sections of your syntax.
  • Sensitivity: Although syntax is not case-sensitive (to the best of my knowledge), syntax code is very sensitive to every other character you type (including periods and other punctuation).

Now, let’s practice. Open a data set and create a new syntax file. Click anywhere in the syntax file’s blank box. Insert a row of asterisks, a description of the file, another row of asterisks, and a period. Save your file somewhere appropriate with an appropriately distinctive file name. Your syntax should now look something like this (click on the image for a larger view).

The next step is to insert code into your syntax file that will specify the types of analyses that the program will conduct on your data. Three general ways that I typically generate code are through (a) directly typing it in from memory, (b) copying, pasting, and editing syntax from another source, and (c) using the program’s “paste” function. I recommend starting your foray into SPSS syntax using methods (b) and (c), which may or may not naturally progress into method (a).

One common task when setting up your data for analysis is properly inputting your variable and value labels. This is helpful because when you run analyses, the SPSS output will include the labels assigned to the variables that were analyzed, assisting in your interpretation of the results. Let’s imagine that one of your variables is “overall satisfaction with life,” being measured by one item on a five-point scale ranging from 1 (strongly disagree) to 5 (strongly agree). Forget, of course, that using a single item to measure a construct is a bad idea from a measurement perspective.

Let’s go ahead and designate a variable in your data set as having the name “lifesat.” Select the “variable view” on the bottom left corner of your data file and type “lifesat” into the upper left cell under “Name.” You can quickly assign labels to both the variable itself and to its values using the syntax below:

variable labels lifesat 'overall satisfaction with life' .

value labels lifesat 1 'strongly disagree' 2 'disagree' 3 'neither agree nor disagree' 4 'agree' 5 'strongly agree'.

To run this syntax, first copy and paste it into your syntax file. Then, simply highlight it and type CTRL+R on your keyboard. You can also select “run” from the menu at the top of the syntax file or click on the right-facing triangle in the menu bar.

An output file should appear which will simply repeat the syntax listed above. Note that you will receive an error message if there is no actual variable named “lifesat.” If you look at the “label” and “values” columns in the data set, the labels and values specified above should now appear.

This procedure is especially useful when setting up an SPSS data file from raw data, which often is in the form of an Excel spreadsheet or comma-separated values (.csv) file. For example, this is specifically how the popular online survey tool SurveyMonkey compiles data for users to download. It is especially helpful when conducting initial SPSS data file setup to list all of the variable names in one column, followed by all of the corresponding variable labels in the adjacent column, and then use the concatenate function in Excel to help create all of the syntax for you. Download this Excel 2007 spreadsheet for a quick template; pay attention to the comments in each cell regarding instructions. Note that the workbook has two spreadsheets, one for variable labels and one for value labels.

I have frequently found these basic SPSS syntax procedures to be useful in the initial-setup phase of data analysis. Future posts will discuss and explore using syntax to actually analyze your data, but these initial procedures are useful because they will aid in the interpretation of those analyses.