SPSS Reading Data

SPSS has a wide variety of commands for reading in external or embedded data.


Embedded Data

The DATA LIST command can be used to read data that is listed between BEGIN DATA and END DATA commands.

data list list / CaseNum (F2) Score (F3).
begin data
1, 10
2, 40
3, 15
4, 10
5, 15
6
7, 25
8, 10
end data.


Fixed Width Data Files

The GET command can be used to read fixed-width data contained in an external file.

get data
  /type=txt
  /file="path/to/data.txt"
  /arrangement=fixed
  /fixcase=1
  /firstcase=2
  /importcase=all
  /variables=
  VAR1 0-2 A
  VAR2 3 F.

Variables should be specified with start and end column indices and a format. If a variable occupies a single column, just specify the index once.

The DATA LIST FIXED command can also be used for this task.

Multi-Record Data

If data for a single case is found on multiple records (i.e. multiple lines), try:

get data
  /type=txt
  /file="path/to/data.txt"
  /arrangement=fixed
  /fixcase=2
  /firstcase=2
  /importcase=all
  /1
  VAR1 0-2 A
  VAR2 3 F
  /2
  VAR3 0-2 A
  VAR4 3 F.

Note also that the /FIXCASE subcommand is updated to 2.


Delimited Data Files

The GET command can be used to read any type of delimited data.

get data
  /type=txt
  /file="path/to/data.txt"
  /arrangement=delimited
  /delimiters=","
  /firstcase=2
  /importcase=all
  /variables=
  VAR1 A1
  VAR2 F2.

A print and write format must be specified for each variable. Note however that numeric variables are read irrespective of the width and decimal places. It can still be meaningful to provide a date or time format to ensure accurate value parsing, and string formats must be accurately declared.

The DATA LIST LIST command can also be used for this task.


CategoryRicottone

SPSS/ReadingData (last edited 2023-06-14 19:30:43 by DominicRicottone)