DROP and KEEP Subcommands (SAVE command)
DROP
and KEEP
are used to save
a subset of variables. DROP
specifies the variables
that are not to be saved in the new data file; KEEP
specifies
the variables that are to be saved in the new data file; variables
that are not named on KEEP
are dropped.
- Variables can be specified in any order. The order of variables
on
KEEP
determines the order of variables in the data file. The order onDROP
does not affect the order of variables in the data file. - Keyword
ALL
onKEEP
refers to all remaining variables that were not previously specified onKEEP
orDROP
.ALL
must be the last specification onKEEP
. - If a variable is specified twice on the same subcommand, only the first mention is recognized.
- Multiple
DROP
andKEEP
subcommands are allowed. If a variable is specified that is not in the active dataset, or that has been dropped because of a previousDROP
orKEEP
subcommand, an error results, and theSAVE
command is not executed. - Keyword
TO
can be used to specify a group of consecutive variables in the active file.
Example
GET FILE='/data/personnel.sav'.
COMPUTE TENURE=(12-CMONTH +(12*(88-CYEAR)))/12.
COMPUTE JTENURE=(12-JMONTH +(12*(88-JYEAR)))/12.
VARIABLE LABELS TENURE 'Tenure in Company'
JTENURE 'Tenure in Grade'.
SAVE OUTFILE='/data/personnel88.sav' /DROP=GRADE STORE
/KEEP=LNAME NAME TENURE JTENURE ALL.
- The variables TENURE and JTENURE are created by
COMPUTE
commands and are assigned variable labels by theVARIABLE LABELS
command. TENURE and JTENURE are added to the end of the active dataset. -
DROP
excludes variables GRADE and STORE from file personnel88.sav.KEEP
specifies that LNAME, NAME, TENURE, and JTENURE are the first four variables in file personnel88.sav, followed by all remaining variables not specified onDROP
. These remaining variables are saved in the same sequence as they appear in the original file.