UCLA Academic Technology Services HomeServicesClassesContactJobs

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.

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.

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 (.). 

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.

2.5  Opening an SPSS data file

Last but not least, here is how to open an SPSS data file.

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

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


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.