Saving data sets
SPSS data sets
If you have read data from a different format than SPSS, or if you have modified an existing SPSS file, you may wish to save your file for further use in SPSS format. This is done with the
SAVE FILE command.
SAVE OUTFILE = 'd:\mydirectory\mysubdirectory\mydata.sav'.
where you have to fill in your directory and data set names. Note that SPSS issues no warning if you overwrite an existing data set, thus be careful in the choice of the name of this data set. Of course, if you have modified an existing data set, using the old name may be exactly what you want. However, this should only be done if you have augmented your data set, i.e. if you have added new variables. If you have changed, or even deleted, old variables, as a beginner you should use a different name for your data set even if you have changed or deleted these variables precisely because you wanted to get rid of them. But perhaps you have committed a mistake and wish to redo your modifications in a different way; this will be impossible if the original variables have not been kept somewhere.
As with the
GET FILE command, the
KEEP, DROP and
RENAME subcommands are available to change your data file during the SAVING process. If you want to get rid of most of your variables, it is useful to indicate which variables you want to KEEP; if you want to keep most of the variables, you will prefer to indicate which variables to DROP. Renaming variables can be useful for various purposes. Here's an example:
|SAVE OUT = 'd:\mydirectory\mysubdirectory\mydata.sav'|
|/ DROP var11 var15 var17 var88|
|/ RENAME (var10 var19 = gender age).|
Note that SAVing your data file does not affect your working file. Thus, if you wish to use the SAVed data set for your next analysis steps, you first have to read in the file anew with the
GET FILE command. This may happen more frequently than you think; for instance, you may have modified your data, and in the process a number of 'intermediate' variables may have been used which are not of interest by themselves, but were needed in one way or other for creating new variables of interest. (For instance, you may wish to compute the overall household income from different types of income of several persons in a household; this may easily amount to hundred variables or more.) But when you have finished your task, these variables are no longer useful and only render your data set unnecessarily large. This is the moment when it is a good choice to SAVe your data and
DROP those variables you don't need any longer (or to
KEEP those with which you wish to pursue your work).
Saving your data in another format
For some reason or other, you may wish to analyze your data with other software. This "other software" may be able to read SPSS data, but much more frequently than not this is not the case. SPSS can assist you by saving the data either in a specific format or in a general format that can be read by most software.
Here is a small selection of possibilities.
Saving data as a Stata™ file
|SAVE TRANSLATE OUT = 'd:\mydir\mystatadata.dta'|
|/ DROP var17 var20 var24|
REPLACE will do what it looks like doing, i.e. any existing file with the same name will be overwritten. Of course, you may omit this command.
Saving data as a comma delimited file
In this type of file, the data will be in 'raw' format, with each data value separated from the next by a comma. This may be read by a variety of other software.
|SAVE TRANSLATE OUT = 'd:\mydir\mycsvdata.csv'|
MAP will produce an exact list of all variables written to the new file. Of course, the
KEEP subcommands may be used as well.
Saving data as a tabulator delimited file
Use the same command as with a comma delimited file, but use
Saving data in a plain ASCII file
To save your data just as raw data and nothing else (no delimiters, no other characters), the command goes like this:
|WRTIE OUT = 'd:\mydir\myasciidata.txt' TABLE|
|/ var1 var17 var18 to var24.|
If you just wish to
WRITE the entire data set, use ALL instead of a varlist.
This procedure will produce an ASCII file in FIXED FORMAT (see section Read Raw Data on how to read such a file). Keyword
TABLE will make SPSS produce an exact description of the data set. Note that
WRITE will be accomplished only upon execution of another command or with the help of
EXECUTE, as demonstrated here.
© W. Ludwig-Mayerhofer, IGSW | Last update: 16 Sep 2009