Loading data using SPSS - instructions for creating a syntax file

Before loading your data into SPSS, unzip your data and convert to *.txt using these instructions.

Creating a syntax file

Step 1

Open SPSS 18.
Skip the intro and navigate to the PASW Statistics Data Editor window.

From the File menu, navigate to New\Syntax.

This screen should open:

The syntax Editor is where you will tell SPSS which data file to open, and how to load the data based on the layout.

You will need your data dictionary to complete the syntax file.

Note: Please refer to your Data Dictionary. It should be located at R:data\Project_Number\docs\data dictionary where you will find an excel file called the Data Dictionary. This file describes the layout of each of your data files.

Note: Most files have only one layout, but for other files (eg. Hospital Separations) you will notice that there are various layouts depending on the year of data.

 

Step 2: tell SPSS where your data file is saved

In the syntax Editor, type the following Data List command, substituting the shaded text with your data directory and file name:

DATA LIST FILE=R:groups\proj_number\Your_Data_Folder\File_Name.txt /

Note: you may want to start with one of your smaller data files. That is, one of the data files that consists of fewer variables. Consult your Data Dictionary.

Step 2: define the variables in the data file selected in Step 1

In the lines below the DATA LIST command you will define the variables. Using the information in your Data Dictionary, you can type in the first data field name and tell SPSS the size of that variable  by defining the columns that variable  will use.

Note: If a variable is a string, you will need to add “(a)” after you specify the columns for that variable. If the variable should be treated as numeric, do not type in the “(a)”.

Note: The Variable Type can also be adjusted later. Once the data has been loaded into the Data Editor, select the “Variable View” tab.

Click on the “Type” for the specific variable you would like to change, you will notice “…” if you click on the “…” a window will open allowing you to choose from ‘String’, ‘Numeric’ and other options.

DATA LIST FILE=R:groups\proj_number\Your_Data_Folder\File_Name.txt /
field1_name 1-3 (a)
field2_name 4-6 (a)
field3_name 5-5 (a)
etc
final_field 152-155(a).
execute

Note: For variables that are only one character in length see “field3_name” above. The column will start and stop at position 5, this will give you a single column or single character length.

Once you have entered all of the variables it is absolutely necessary to put a full stop “.” after the final (a) or after the final column numbers. This tells the program that you have defined all of the variables.

Then type “execute” below.  This is an action command for the program.  The word execute should turn red.

Example:
DummyData Dictionary

Start Stop Length Fieldname Notes
1 3 3 Postal_Code (3 digit)  
4 7 4 Source  
8 9 2 Version  
10 19 10 Sequence_Number  
20 29 10 Study_ID  
30 30 1 Line_Feed Do not enter the line feed into the syntax editor. It is not a variable.

Sample Syntax Editor

Step 4: Save your syntax file

Navigate to the file menu select “Save As” and save this file in your preferred folder on the R: drive.

You will want to name the file according to the Data File the syntax refers to and the Year of data you have specified in Step 1. (example – Hospital1989_90.A.sps etc)

Step 5: Create a syntax file for every year of data applicable to the layout you have created

You will need to create a syntax file for all the years of data within a layout and for each layout.

For example, if you have Hospital data from 1993/94 to 2008/09 you will notice your Data Dictionary has layouts A, D, E and F. For all the years in the A layout it is as simple as editing the Data List command line to show the subsequent file year and then saving the syntax file with a new file name noting the applicable year. (example hospital1993_93.A.sps, hospital1994_95.A.sps, hospital1995_96.A.sps etc).

To create a syntax file for a new file layout, go back to the beginning of the instructions and create a new syntax file for the new layout.

Loading your data using your syntax file

Step 1

Once you have completed all of the necessary syntax files (or you are ready to test the first one).

Navigate to the Syntax File on the R: drive and double click, this will open the Syntax Editor. Or if you still have the Syntax file open ensure that it has been saved.

Next you will want to run your Syntax file.

Navigate to Run menu bar and select “All”. Depending on the size of your file this step may take a few minutes.

An Output document will open automatically, once your data has been loaded to let you know if there have been any errors:

 

You should then be able to open the Data Editor Window and see your data:

Next steps

Go back to the beginning of this document to create a syntax file for each data layout.

If you have any questions please contact the Researcher Liaison Unit at rlu@popdata.bc.ca