SPSS files normally have an .sav extension but may also have a less common .por extension (an ASCII-based format that facilitates transporting to other computers and operating systems without problems.)
In the Windows/Mac versions the OPEN command with in file menu will read SPSS formats and SAS, Stata, Excel, and dBase formats. The SAVE and SAVE AS commands can write files out in all these formats.
If you have raw data, you will have to do all the work of defining the variables yourself, i.e, write a program. When reading or writing af file in a SPSS program you must use the name of the file and its location (path). Examples are:
- file1.dat
raw data file located in your directory
- file1.sav
SPSS data file located in your directory
- surveys/file1.sav
SPSS data file located in a subdirectory of your home directory
- /u/9/s/me2000/surveys/file1.sav
SPSS data file located in a subdirectory of your home directory, with a full path name
SPSS program files cannot read files in SAS, Stata, Excel, and dBase formats. They can read SPSS formats and ASCII fixed format or delemited files.
If you are reading an SPSS .sav file you need
- Documentation listing the variables you want and their mnemonic names in the system file.
- An SPSS program with
- a GET FILE = command with the name of the save file in quotes,
- (optional) a /KEEP (or /DROP) subcommand with the names of the variables you
want to use (or not use). If you need all the variables, leave this out.
- a period to end the command.
Example:
GET FILE="/u/9/s/me2000/surveys/file1.sav"
/KEEP zodiac sex.
If you are reading raw (ASCII) data you need
- Documentation describing the variables.
- Mnemonic names for the variables you want (up to 8 characters each only) with
- Each variable's column position(s) in the file, e.g. 1-4, and
- Each variable's type, i.e., integer, decimal, or alphanumeric.
You make up the names. You can use V[n] to V[m], e.g., V1 to V100, if you want,
but using mnemonic names is a lot easier in the long run. You don't have to define all
the variables in your file, just the ones you need.
- The length of the records in the file (the LRECL).
- An SPSS program with
- A FILE HANDLE command with
- a "handle" (IN for the example below),
- a "/" (slash),
- a NAME= subcommand with the name of the raw data file in quotes,
- the LRECL= subcommand, and
- a period to end the command.
- A DATA LIST command with
- a FILE=handle subcommand,
- a "/" (slash), and
- then the list of the mnemonic variable names, each followed by its column positions, and its type if it has a decimal place or is an alphanumeric, and
- a period to end the command.
Example:
FILE HANDLE MYFILE/NAME="file1.dat" lrecl=1200.
DATA LIST FILE=MYFILE /
PERSONID 1-4
SEX 6
BIRTHYR 7-10
INCOME 15-21 (2)
STATE 55-56 (A).
In the example above, INCOME has 2 decimal places and STATE is a 2 column character variable. Note that you don't have to define all the variables in your file, just the ones you need.
- Some raw data files can have multiple lines of data for each case. This frequently happens with opinion surveys where the responses from one respondent are reported on two or three lines (in the documentation often referred to as "records" or "cards"). Use the subcommand RECORDS= following the DATA LIST command.
- a records=# subcommand placed after the file handle, with # = the
number of records per case,
- a "/" (slash) marking the start of each record followed by an
integer that indicates which record it is.
Example:
FILE HANDLE MYFILE/NAME="file3.dat".
DATA LIST FILE=MYFILE records=3
/1
P-ID-REC1 1-4
SEX 6
BIRTHYR 7-10
INCOME 15-21 (2)
STATE 55-56 (A)
/3
P-ID-REC3 1-4
industry 5-8
occup 9-11.
In the example above, there are three records per case. Note that no variables
are defined for record type=2. You only need to define the variables you need.
If you are reading an SPSS portable file you need
- Documentation listing the variables you want and their mnemonic names in the portable file.
- An SPSS program with
- an IMPORT FILE= command with the name of the portable file in quotes,
- (optional) a /KEEP (or /DROP) subcommand with the names of the variables
you want to use (or not use). If you need all the variables, leave this out.
- a period to end the command.
Example:
IMPORT FILE="/eds/datasets/gss/data/gss94-all.por"
/KEEP zodiac sex.