SPSS Class Notes
Entering Data


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_data\hs0.xls       
         Open
          check "Read variable names from the first row of the data"
           click on OK
* read in an excel (.xls) file.
get data 
 /type=xls
 /file = 'c:\spss_data\hs0.xls'
 /sheet=name 'hs0'
 /readnames=on.
 

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_data\hs0.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..."
* read in a text file.
get data  
 /type = txt
 /file = 'c:\spss_data\hs0.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.

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
        Enter the syntax to the right
data list fixed file="c:\spss_data\schdat.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_data\hs0.sav       
            Open
* how to open an SPSS data file.
get file 'c:\spss_data\hs0.sav'.


If you are using syntax, you will want to have the method of opening the data at the top of your syntax file.  Please note that SPSS can have multiple data files open at once, and your syntax will operate on the active data set. 

3.0 Syntax version

* read in an excel (.xls) file.
get data 
 /type=xls
 /file = 'c:\spss_data\hs0.xls'
 /sheet=name 'hs0'
 /readnames=on.

* read in a text file.
get data  
 /type = txt
 /file = 'c:\spss_data\hs0.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_data\schdat.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_data\hs0.sav'.

4.0 For more information

How to cite this page

Report an error on this page or leave a comment

The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.