Converting ICPSR Data in ASCII Format into SPSS Data Files
(by Özlem Elgün)

Oftentimes, data for an ICPSR study will be available only as a large ASCII text file that looks something like this. These files, which we will often refer to as "raw" data files, are in a "State of Nature" and are, in their present form, unusable by a statistics package such as SPSS. Thankfully, however, the ICPSR usually also has a "setup" file (also referred to here as a syntax file) that will read the raw data into something SPSS can make sense of and use for analysis - a Leviathan, if you will. This page will walk you through the process of how to use and edit SPSS setup files from the ICPSR to extract oneself from the "State of Nature" and create usable SPSS data files.

Start by downloading the data file and SPSS program file from the ICPSR website for the study you want to download. Here, we are using ICPSR #4262:



Click here for full-size image

Once you have located a data file you want to download, click on the "Download" tab. You will be taken to an "Authorized Download - Emory University" page that will ask you for the username and password for your ICPSR account. All ICPSR users are required to have such accounts if they wish to download data, so you will need to set one up if you do not have one already. Enter your username and password and, once you have been authenticated, you will see something like the following screen:



Click here for full-size image

The ICPSR presents users with multiple options for downloading data. Generally speaking, the ICPSR will have files available for different statistical packages. Here, for instance, there are ASCII data and setup files available for SAS, SPSS, and Stata as well as a SAS "transport" file, an SPSS portable file, and a Stata data file. [You can get additional detail about the files available for a study by reading the file manifest that is available on the "Description" page.] You can download just those files for a particular program (e.g. "ASCII Data File and SPSS Setup Files" or "SPSS Portable File") or download all the available files for a particular study. Whichever files you select will then be added into your "data cart" for download. If you go the data-cart route, you will be downloading a zipped archive of whatever files you chose. Alternately, you can click on the "download individual files" link at the right and download files one at a time. For our purposes, we only want the raw ASCII data file and the SPSS setup file, so we will choose this last route. Click on the "download individual files" link and you will be taken to this page:



Click here for full-size image

If you scroll down you will see that an ASCII data file and an SPSS setup file are available and ready to download.



Click here for full-size image

Now we can save the data and the SPSS setup file. To save the raw data file, click on the "Data" link and choose "Save Target As...":



Click here for full-size image

Save the data in the desired location in your computer. For our example here, we're saving all our files to "C:\patrons\oelgun\STATA_and_SPSS_tutorials\ICPSR_4262_data\4262". Be sure to add ".txt" to the end of the filename - the "Save as Type" field should be "Text Document". Here, we'll save the data file as "sp4262-Data.txt":



Click here for full-size image

[Note that in this tutorial, we are not using the default file names (e.g. 04262-0001-Data.txt for the data file) that the ICPSR assigns. Instead, we are using an older ICPSR convention for naming files, mainly because the resulting file names are shorter. How you wish to name the files is up to you - just be careful about what file extension you specify.]

Next, we need to save the "SPSS setup" file, which is the SPSS command file that we will use to move the raw ICPSR data into SPSS. Save the command file by right-clicking on the "SPSS setup" link and saving it to your hard drive. Here, we will name the file "sp4262-Setup.sps." Be sure to add ".sps" to the end of the filename; otherwise, SPSS will not recognize the file as a SPSS syntax file. So, the "Save as type" field should be either "All Files" or "SPSS Syntax Document" (either option will work - just make sure you attach the .sps extension):



Click here for full-size image

[Note - for reference, SPSS syntax files have a .sps extension, while SPSS data files have a .sav extension, or a .por extension if they are "portable" files. SPSS output files, which contain tabular or graphical output from SPSS commands and procedures, have .spo extensions.]

Now, you need to edit the SPSS syntax file that you have downloaded so that it will read the raw data file that you want to analyze. To open the SPSS syntax file, open up SPSS, then click on the "File" menu, choose "Open" and choose the "Syntax…" option:



Click here for full-size image

Locate the SPSS syntax file that you saved previously, select it, and click on "Open":



Click here for full-size image

When you open the syntax file, it should look something like this:



Click here for full-size image

At the top of the file, there will often be descriptive text that is "commented out" by asterisks and will not be processed by SPSS when we run the command file. Generally, such text contains descriptions of the study and/or some instructions for the user. Sometimes, however, the ICPSR will also comment out commands that you may want to use when reading the data into SPSS. Text and commands that are commented out are usually preceded by an asterisk (*). If you remove the *, SPSS will then read those lines when running the command file (assuming that this is what you want to do - if it isn't, then do not remove the asterisks). [Note - not every SPSS syntax file from the ICPSR will include a descriptive section.]

As you scroll down the syntax file, you should encounter FILE HANDLE and DATA LIST commands such as the following:



Click here for full-size image

The FILE HANDLE command will assign a unique handle to an external file located at a particular folder. You can think of this "handle" as a nickname referring to a particular file at a particular location. FILE HANDLE also often supplies technical specifications for the file. At the end of our FILE HANDLE command here, for instance, you will see an LRECL (logical record length) statement. This statement tells SPSS how many columns there are in the raw data file (in our example file, for instance, the logical record length of the raw data file is 2576). The DATA LIST command will then actually read in and process the raw data file. It will create variables and name them, tell SPSS where the variables are located in the raw file, and also perform tasks such as assigning formats to the variables (e.g. make the variables numeric or string or whatever). The FILE statement in the DATA LIST command should thus refer to the file handle you've just defined.

FILE HANDLE commands generally look something like this:

FILE HANDLE handle-name / NAME=" location-and-name-of-raw-datafile" LRECL="# of columns".

In our example below, we will assign the file handle "DATA" (no, not that one) to the raw data file we have saved. We don't actually have to call the handle DATA, by the way - we could give it a different name. "DATA" is the default ICPSR name for file handles, however, and we'll stick with it here. So, our FILE HANDLE command here needs to look as follows:

FILE HANDLE DATA / NAME=" C:\patrons\oelgun\STATA_and_SPSS_tutorials\ICPSR_4262_data\4262\sp4262-Data.txt" LRECL=2576.

[Note that SPSS requires that each command ends with a "." (a period). The period is the symbol that tells SPSS that one command has ended and another will begin. If you do not end commands with a period, SPSS will not be able to determine when one command ends and another begins and will throw a major fit. Suffice it to say that hilarity will not ensue.]

DATA LIST commands, meanwhile, generally start with a line that looks something like the following:

DATA LIST FILE=file-handle-name /

So, you need to edit the DATA LIST command to refer to the handle you've defined. Since we've assigned the handle "DATA" to our raw data file, our DATA LIST command should start as follows:

DATA LIST FILE = DATA /

with the remainder of the command telling SPSS where the variables are located in the raw data file, what they are named, and so on. So, once we are done editing our FILE HANDLE and DATA LIST commands, our syntax file should look as follows:



Click here for full-size image

[Note - many ICPSR SPSS syntax files will include only the DATA LIST command and will not include the FILE HANDLE command. In these situations, all you need to do is modify the FILE= statement to tell SPSS where your raw data file is located and what its name is: DATA LIST FILE = "location-and-name-of-raw-datafile" If, for example, our syntax file here did not include a FILE HANDLE command, we would instead edit the DATA LIST command to point to our raw data file:

DATA LIST FILE = "C:\patrons\oelgun\STATA_and_SPSS_tutorials\ICPSR_4262_data\4262\sp4262-Data.txt" /]

As you scroll down an SPSS syntax file from the ICPSR, you will generally see a VARIABLE LABELS command:



Click here for full-size image

This section assigns descriptive labels to variables in the raw data file. You generally do not need to make any changes to this command. Depending on the number of variables, this section can be long. As you scroll down, note that the command line ends with a period:



Click here for full-size image

With SPSS syntax files from the ICPSR, you will also generally see a VALUE LABELS command:



Click here for full-size image

This command assigns descriptive labels to values for categorical variables and can be very useful when displaying summary reports of your data. You generally do not need to make any changes to this command. Once again, note that the command line ends with a period:



Click here for full-size image

[Note - you will also often encounter a MISSING VALUES command that tells SPSS which codes or values for a variable represent missing data. In this particular example, however, there is no such section in the syntax file. Also note that, by default, the ICPSR often comments out this section of a syntax file with an asterisk; thus, the command will not necessary be executed when you run the command file.]

Now, we need to tell SPSS to save our new data file. In order to do this we need to use the SAVE OUTFILE command, which generally should like this:

SAVE OUTFILE = "location-and-name-of-SPSS-datafile".

The ICPSR may already have included this command towards the end of the syntax file. If this command is not already included in the SPSS syntax file, you will need to add it yourself; otherwise, the SPSS data file that you are creating will not be saved when you close SPSS. Either way, you will need to tell SPSS where you want to save your file and what you want to call it. In our example, we will edit the SAVE OUTFILE command line as follows:

SAVE OUTFILE=" C:\patrons\oelgun\STATA_and_SPSS_tutorials\ICPSR_4262_data\4262\sp4262-Data.sav".

Once again, what you want to call the file is up to you. You must, however, give the file a .sav extension to ensure that it is saved as an SPSS data file. Also, make sure that your command line ends with a period.

Finally we need to add the EXECUTE command to your syntax file, which tells SPSS to "execute" the preceding commands in the file. (If you are familiar with SAS, EXECUTE is similar to RUN in that program.) Most of the time, you will need to add these command yourself. Make sure that you include it after the SAVE OUTFILE command - all you need to do it type "EXECUTE" and add a period at the end. So, once we are done editing/adding the SAVE OUTFILE and EXECUTE commands, our syntax file looks as follows:



Click here for full-size image

When you have finished editing the SPSS syntax file, it's generally a good idea to save your changes to it. So, go to "File" menu and choose the "Save" option:



Click here for full-size image

Now, we are ready to run our syntax file to create and save our data. To run the syntax file, go to the "Run" menu at the top of the syntax-editor window and choose the "All" option:



Click here for full-size image

Assuming that there are not any mistakes in the syntax file (admittedly, not always a good assumption!), the syntax file will then read in the raw data to create and save a data file ready for use in SPSS:



Click here for full-size image

To learn more about the syntax for these SPSS commands, you can use the internal syntax reference guide which is available in SPSS. Click on the "Help" menu in SPSS' Data Editor and then choose "Command Syntax Reference" and the syntax reference guide will appear as a (very large) .pdf file:



Click here for full-size image

Click here for full-size image

Sample SPSS Syntax Files:

Below are some sample SPSS syntax files that will read raw ICPSR data into SPSS. The files were downloaded from the ICPSR and edited by the EDC staff in the manner described in this guide. To save any of these files, right-click on the appropriate link and choose "Save Target As..." (in Internet Explorer) or "Save Link Target As..." (Netscape) and choose a location to save the file(s). The files are for illustrative purposes.

SPSS Syntax File for ICPSR #3930 - Eurobarometer 59.1: The Euro and Parental Leave, March-April 2003

SPSS Syntax File for ICPSR #4055 - Candidate Countries Eurobarometer 2003.3, June-July 2003

SPSS Syntax File for ICPSR #4236 - Afrobarometer: Round II Survey of South Africa, 2002

The ICPSR also has a help guide for working with its SPSS syntax files at http://webapp.icpsr.umich.edu/cocoon/ICPSR-FAQ/0062.xml that you might find useful. Note that not every SPSS syntax file that the ICPSR distributes follows the exact format of the file we've been looking at here - there is a fair amount of variation across studies, especially with older studies that have syntax files written for older versions of SPSS with different syntax rules. If you would like additional assistance, please feel free to contact the Data Center staff.



Home | Analyze Data Online | Help Resources | Contacts & Hours | Emory General Libraries