UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

SPSS Class Notes
Entering Data


1.0 Demonstration and explanation

We will start with inputting an Excel file. The variable names are on the first line of the Excel 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.

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

data list fixed file="c:\spss\schdat.fix"
 / id 1-2 a1 3-4 t1 5-6 gender 7 a2 8-9 t2 10-11 tgender 12.
list.

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.

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.

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

2.0 Syntax version

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

* read in a text file.
get data  
 /type = txt
 /file = 'c:\spss\hs0.csv'
 /delimiters = ","
 /firstcase = 2
 /variables =
 v1 f1.0
 v2 f3.2
 v3 f1.0
 v4 f1.0
 v5 f1.0
 v6 a10
 v7 f2.1
 v8 f2.1
 v9 f2.1
 v10 f2.1
 v11 f2.1.
execute.

* read in a filed format ascii file.
data list fixed file "c:\spss\schdat.fix"
 / id 1-2 a1 3-4 t1 5-6 gender 7 a2 8-9 t2 10-11 tgender 12.
list.

* 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.
get file 'c:\spss\hs0.sav'.

3.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