File Handling
SPSS® Reference Manual: A guide for market researchers
Prepared by Paul Hartzer
Contents
Opening an existing SPSS datafile
GUI method
- On the menu, select File.
- Select Open > Data...
- Using the standard Open File wizard, find the file that you want to open.
- Select Open.
Syntax method
GET FILE=''.
Example:
GET FILE='C:\Documents and Settings\User\My Documents\'+
'Feb Inter.sav'.
Opening an existing syntax file
GUI method
- On the menu, select File.
- Select Open > Syntax...
- Using the standard Open File wizard, find the file that you want to open.
- Select Open.
Syntax method
(N/A)
Creating a new SPSS datafile
GUI method
- On the menu, select File.
- Select New > Data.
Syntax method
NEW FILE.
Creating a new syntax file
GUI method
- On the menu, select File.
- Select New > Syntax.
Syntax method
(N/A)
Loading an existing flat ASCII datafile (advanced)
GUI method
- On the menu, select File.
- Select Open > Data...
- Select All Files in the Files of type: drop-down.
- Using the standard Open File wizard, find the file that you want to open.
- Select Open.
- In step 1, select No and click Next>.
- In step 2, select Fixed width and No and click Next>.
- In step 3, make sure the first two values are 1, and select All of the cases. Click Next>.
- In step 4, move, create, and remove solid lines to mark off your data, using the data map associated
with the file you're loading. Click Next>.
- In step 5, name the variables, and delete any you don't want to load.
(Hint: This can be done later in the GUI, where it'll be easier.) Click Next>.
- In step 6, check Yes or No as desired in the first two boxes, then click Finish.
Syntax method
Note: If you use Paste in step 11 of the GUI Method, you will get syntax that is different from this
(see "notes" below).
DATA LIST FILE='' / Variable1 1-5.
Example:
DATA LIST FILE= "\\Ndtsnt-fs--164\CSG\Chevrolet_AWGL.asc"/
RESPID 8-10
ADCODE 1-7 (A)
LANGUAGE 450.
Notes:
This is for data where there is one row per respondent; loading data from card formatted files (multiple
rows per respondent) is more difficult, and is not covered in this section.
If you paste, you will get the GET DATA command instead.
GET DATA offsets the columns by 1, so ADCODE in
the example would be in 0-6 instead of 1-7. This can be confusing, and is best avoided.
(A) in the syntax indicates that the variable is text, instead of a number.
Merging multiple files--Adding respondents
This is done when you have two files that have the same variables for different respondents.
GUI method
- Open one of the files involved.
- On the menu, select Data.
- Select Merge Files > Add Cases...
- Using the standard Open File wizard, find the file that you want to merge in.
- Select Open.
- On the left are any variables that are only in one of the files. (*) indicates that the
variable is only in the file from step 1; (+) indicates that the variable is only in the file
from step 5. If you want to include any of these variables, move them to the right with the arrow button.
- On the right are the variables that will be merged. If you want to exclude any of these, move them to
the left with the arrow button.
- Ignore the check box.
- Click OK.
Syntax method
In this case, the syntax allows more flexibility than the GUI. For instance, if you want to
merge one file into a file that's already open, do this (the merged file will contain all
variables from both files):
GET FILE=''.
ADD FILES /FILE=*
/FILE=''.
Do this if you want to create a new file consisting of multiple files:
ADD FILES /FILE=''
/FILE=''
/FILE=''.
If you want to drop specific variables, use the /DROP command:
ADD FILES /FILE=''
/FILE=''
/DROP= varname1 varname2.
If you only want to include a small number of variables, use /KEEP instead of /DROP.
Merging multiple files--Adding variables
This is done when you have two files that have different variables for the same respondents.
GUI method
- Open one of the files involved.
- On the menu, select Data.
- Select Merge Files > Add Variables...
- Using the standard Open File wizard, find the file that you want to merge in.
- Select Open.
- On the left are any variables that are only in one of the files. (*) indicates that the
variable is only in the file from step 1; (+) indicates that the variable is only in the file from step 5.
If you want to include any of these variables, move them to the right with the arrow button.
- On the right are the variables that will be merged. If you want to exclude any of these, move them
to the left with the arrow button.
- The default is to merge files one-to-one: The first records will be combined, then the second,
and so on. If this is what you want to do, skip step 9.
- More often, though, you'll want to merge based on a specific variable, such as respondent ID.
To do this, click on Match cases on key variables in sorted files, and then move the variable to the
Key Variables box.
- IMPORTANT NOTE: The two files must be sorted on this variable.
Otherwise, you'll get an error.
- If there are unmatched records (one file doesn't contain information on the same respondents),
choose whether to include all respondent data, or only data for respondents from one file.
- Click OK.
- If you are matching cases, click OK to the warning message.
- When asked if you want to save the contents of the data file, say no.
Syntax method
Note that the command here is different. Instead of ADD, it's
MATCH. If you just want to match one-to-one (as in step 8 above),
don't include the /BY line.
GET FILE=''.
MATCH FILES /FILE=*
/FILE=''
/BY .
As with ADD, MATCH allows you to specify more than two files.
Saving an SPSS datafile
Note that when you close SPSS, you will be prompted to save any unsaved files.
GUI method
- On the menu, select File.
- Select Save (or Save As...).
- Using the standard Save File wizard, find the directory and name the file.
- Select Save.
Syntax method
SAVE OUTFILE=''.
Use /DROP to exclude some variables from the save (VAR1 and VAR2 won't be saved):
SAVE OUTFILE='' /DROP VAR1 VAR2.
Use /KEEP to only save specific variables (VAR1 and VAR2 will be the only variables in the file):
SAVE OUTFILE='' /KEEP VAR1 VAR2.
Hint: If you want to change the order of the variables in the file,
use /KEEP and list all the variables in the file, in the order you want them in.
Saving a syntax file
Note that when you close SPSS, you will be prompted to save any unsaved files.
GUI method
- From the syntax window, on the menu, select File.
- Select Save (or Save As...).
- Using the standard Save File wizard, find the directory and name the file.
- Select Save.
Syntax method
(N/A)
Exporting SPSS data to ASCII
GUI method
- On the menu, select File.
- Select Save As....
- Using the standard Save File wizard, find the directory and name the file.
- Select Fixed ASCII (*.dat) from the Save as type drop-down list.
- Select Save.
Syntax method
WRITE OUTFILE='' /ALL.
If you only want to keep certain variables, list them instead of using /ALL:
WRITE OUTFILE='' /RESPID VAR1 VAR2.
Return to Contents - Back to Introduction - Continue to Data Manipulation