1.0 SPSS commands in this unit
get data | used to read in data in different formats, such as Excel and comma separated values (.csv) |
data list | used to read in data that are in fixed or list format |
list | lists the data in the output window |
get file | used to read in data that are in an SPSS data file |
2.0 Demonstration and explanation
In this unit we will show several ways of getting data into SPSS.
2.1 Reading in an Excel file
We will start with inputting an Excel file. The variable names are on the first line of the Excel file.
-
File Open Data from "Files of type", select Excel .xls format select File: c:spss_datahs0.xls Open check "Read variable names from the first row of the data" click on OK
2.2 Reading in a comma-separated-values text file
A comma-separated-values (.csv) format data file is a text data file and can be read in as follows. The variable names are on the first line of our data file hs0.csv. The same procedure will also work with tab-delimited data files.
-
File Read Text Data from "Files of type:" select All Files(*.*) select File: c:spss_datahs0.csv Open click on "Next..." on step 2 of 6, click on "yes" to the question "Are variable names included at the top of your file?" On step 3 of 6, at the top of the dialogue box, make sure to indicate that the first case of data is on line 2. You can accept all other defaults and continue clicking on "next" through the remaining steps click on "Finish..."
2.3 Reading in an ASCII fixed-format text file
The other type of commonly used ASCII data format is fixed format. It always requires a codebook to specify which column corresponds to which variable. Here is small example of this type of data with a codebook. One way of inputting this type of data is through the syntax editor.
195 094951 26386161941 38780081841 479700 870 56878163690 66487182960 786 069 0 88194193921 98979090781 107868180801
variable name column number id 1-2 a1 3-4 t1 5-6 gender 7 a2 8-9 t2 10-11 tgender 12
You will need to open a new SPSS syntax editor into which you can type the following code. Remember that each command in SPSS must end in a period (.).
-
File New Syntax data list fixed file="c:spss_dataschdat.fix" / id 1-2 a1 3-4 t1 5-6 gender 7 a2 8-9 t2 10-11 tgender 12. list /cases = from 1 to 10.
2.4 Inputting data via the syntax editor
Using syntax editor, we can also input data directly. You can copy and paste the syntax below to the syntax editor and run it. Notice the difference in syntax between a numeric variable and a character variable.
-
File New Syntax Enter the syntax to the right data list list /id female race ses * schtype (A3) prog read write math science socst. begin data. 147 1 1 3 pub 1 47 62 53 53 61 108 0 1 2 pub 2 34 33 41 36 36 18 0 3 2 pub 3 50 33 49 44 36 153 0 1 2 pub 3 39 31 40 39 51 50 0 2 2 pub 2 50 59 42 53 61 51 1 2 1 pub 2 42 36 42 31 39 102 0 1 1 pub 1 52 41 51 53 56 57 1 1 2 pub 1 71 65 72 66 56 160 1 1 2 pub 1 55 65 55 50 61 136 0 1 2 pub 1 65 59 70 63 51 end data.
2.5 Opening an SPSS data file
Last but not least, here is how to open an SPSS data file.
-
File Open Data select File: c:spss_datahs0.sav Open
3.0 Syntax version
* read in an excel (.xls) file. get data /type=xls /file = 'c:spss_datahs0.xls' /sheet=name 'hs0' /readnames=on. * read in a text file. get data /type = txt /file = 'c:spss_datahs0.csv' /delimiters = "," /firstcase = 2 /variables = gender f1.0 id f3.0 race f1.0 ses f1.0 schtype f1.0 prog a10 read f2.0 write f2.0 math f2.0 science f2.0 socst f2.0. execute. * read in a filed format ascii file. data list fixed file "c:spss_dataschdat.fix" / id 1-2 a1 3-4 t1 5-6 gender 7 a2 8-9 t2 10-11 tgender 12. list /cases = from 1 to 10. * input data directly using the syntax editor. data list list /id female race ses * schtype (a3) prog read write math science socst. begin data. 147 1 1 3 pub 1 47 62 53 53 61 108 0 1 2 pub 2 34 33 41 36 36 18 0 3 2 pub 3 50 33 49 44 36 153 0 1 2 pub 3 39 31 40 39 51 50 0 2 2 pub 2 50 59 42 53 61 51 1 2 1 pub 2 42 36 42 31 39 102 0 1 1 pub 1 52 41 51 53 56 57 1 1 2 pub 1 71 65 72 66 56 160 1 1 2 pub 1 55 65 55 50 61 136 0 1 2 pub 1 65 59 70 63 51 end data. * open a SPSS data file. get file 'c:spss_datahs0.sav'.
4.0 For more information
- SPSS Programming and Data Management, Fourth Edition
- Chapter 3
- SPSS Learning Modules
Inputting raw data into SPSS
Inputting data directly into the SPSS Data Editor
Reading dates into SPSS and using date variables