Please note the assumptions that went into the creation of this document: it is assumed the user has access to SPSS software and has some basic SPSS experience. Also, please note that this procedure is based on Roper Center datasets only and we recommend the use of the SPSS Syntax file over the SPSS Wizard for more satisfying results.
The Best Way to Approach This Task
- Review the study documentation (also referred to as the codebook) first to identify the questions you want to analyze in SPSS. The codebook fully describes the dataset. It includes information regarding the survey including the study number, title, name of the survey organization that conducted the study, the sponsor (if applies), the field dates, type of sample(s), sample size, type of interview, weight information, and number of records per respondent. The study methodology and any usage notes may also appear. The codebook/questionnaire includes the question numbers, question text, responses including the codes and labels, as well as the card and column locations for each variable. Some studies may include a list of variables and the card and column location for each variable. The back of the codebook includes a dump of the data referred to as an x-ray which shows the un-weighted number of cases in each punch for each column.
- Download both the documentation and data file at the same time
- Based on the number of records per respondent listed on the codebook cover page, determine the appropriate SPSS Syntax file needed (single record or multi-record)
- Use the examples and rules provided to create the required SPSS Syntax file.
- Weighting – If the codebook indicates there is a weight variable, the analysis should be run weighted in order to make the responses be representative of the population surveyed, and to replicate the responses published by the survey organization.
We will focus on “determining the appropriate SPSS Syntax file needed” and “creating the required SPSS Syntax file”.
ASCII Data Files
ASCII data files are often referred to as “text” files or “plain text” files. They contain no formatting information–just rows of characters. The “mapping” information for the characters comes from the codebook discussed in step one above.
- Single Record – respondent’s output is recorded on one line or row
- Multi-Record – respondent’s output is recorded on more than one line or row
Is the ASCII Single Record or Multi-Record?
Refer to the codebook cover page where the number of records per respondent is listed. If this number is “1” the file is a single record file, otherwise it is a multi-record file.
Bringing ASCII Data into SPSS
SPSS Syntax File
Since no structure is included in an ASCII data file, an SPSS syntax file (also known as a setup file) must be created to instruct the software on where to go to get particular variables (questions).
SPSS Commands That Every SPSS Syntax File Should Have
- File Handle – Creates a unique file definition to be referenced in the program. It includes the ASCII data file name and the path the program will use to locate it.
- Data List – Defines the variable names, column locations and data formats
- Variable Labels – Assigns descriptive labels to variables in the dataset
- Value Labels – Assigns response labels for each variable
- Execute. – All SPSS syntax files end with Execute.
|Example of a Single Record SPSS Syntax File|
/* this program reads a single record data file */
Common Errors Found in a single record SPSS syntax file
SPSS Syntax Rules
- Variable names can be up to 8 characters in length but may not start with a number, spaces, &, @, etc.
- A command ends with a period (“.”)
- Command syntax is case insensitive
- Quotes can be single or double but must match. Using ‘single’ and then “double” quotes is acceptable, but you may not ‘combine” them in the same statement
- Comments start with /* and end with */
- The SPSS Syntax file extension is .sps
Run the Syntax File
Highlight all of the syntax file text and click the icon (Run) on the upper menu or select "Run" from the menu. When no errors are encountered processing the file, the data will automatically display in SPSS.
Example of Multi-Record SPSS Syntax File
/* this program reads a multiple record data file */
Common Errors Found in a multi-record SPSS syntax file
Tips & Troubleshooting
- If running the SPSS syntax file produces errors, follow the error detection process below:
- Highlight only the File Handle & Data List text and hit the right facing arrow, the run button, on SPSS to see if the errors fall within this section of the syntax file. If there are no errors in this section continue on.
- Highlight only the File Handle, Data List and Variable Labels text and hit the right facing arrow, the run button, on SPSS to see if the errors fall within this section of the syntax file. Continue with this process until the errors have been identified and corrected.
- For assistance in identifying areas of a syntax file prone to errors, refer to the contents of the following sections:
- Common Errors—Single Record SPSS Syntax File
- Common Errors—Multi-Record SPSS Syntax File
- SPSS Syntax Rules
- If this is your first attempt at writing an SPSS Syntax file, run the file after 1-2 questions to make error identification easier. Once the file is error free you can add additional questions and run the file again, continuing the process until all questions have been included.
- The principles outlined here for SPSS apply to SAS and STATA as well. The syntax will be different, but the principles are the same.
Complete SPSS Syntax Files with ASCII Data File and Codebook
- Single Record SPSS Syntax File and Dataset Abstract
- ABC News/Washington Post Poll # 1991-9142: Thomas Vote Delay Poll #1, October 8, 1991
- Study # USABCWASH1991-9142
- Multi-Record SPSS Syntax File and Dataset Abstract
- Gallup/CNN/USA Today Poll # 1998-9808026: Anti-Terrorist Air Strikes, August 20, 1998
- Study # USAIPOCNUS1998-9808026
Additional SPSS Resources
Research Technologies at Indiana University (http://www.indiana.edu/~statmath/stat/spss/win/index.html)
UCLA Academic Technology Services (https://campusservices.ucla.edu/information-technology-services)