DROP and KEEP Subcommands (XSAVE command)

DROP and KEEP are used to save a subset of variables. DROP specifies the variables not to save in the new data file, while KEEP specifies the variables to save in the new data file; variables 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 on DROP does not affect the order of variables in the data file.
  • Keyword ALL on KEEP refers to all remaining variables not previously specified on KEEP. ALL must be the last specification on KEEP.
  • If a variable is specified twice on the same subcommand, only the first mention is recognized.
  • Multiple DROP and KEEP subcommands are allowed. Specifying a variable that is not in the active dataset or that has been dropped because of a previous DROP or KEEP subcommand results in an error, and the XSAVE command is not executed.
  • Keyword TO can be used to specify a group of consecutive variables in the data file.

Dropping a Range of Variables

XSAVE OUTFILE='/data/hubtemp.sav' 
  /DROP=DEPT79 TO DEPT84 SALARY79.
CROSSTABS DEPT85 TO DEPT88 BY JOBCAT.
  • The data file is saved as hubtemp.sav. All variables between and including DEPT79 and DEPT84, as well as SALARY79, are excluded from the data file. All other variables are saved.

Specifying Variable Order With XSAVE

GET FILE='/data/prsnl.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'.
XSAVE OUTFILE='/data/prsnl88.sav' /DROP=GRADE STORE
 /KEEP=LNAME NAME TENURE JTENURE ALL.
REPORT FORMAT=AUTO /VARS=AGE TENURE JTENURE SALARY
 /BREAK=DIVISION /SUMMARY=MEAN.
  • Variables TENURE and JTENURE are created by COMPUTE commands and assigned variable labels by the VARIABLE LABELS command. TENURE and JTENURE are added to the end of the active dataset.
  • DROP excludes variables GRADE and STORE from file PRSNL88. KEEP specifies that LNAME, NAME, TENURE, and JTENURE are the first four variables in file prsnl88.sav, followed by all remaining variables not specified on DROP. These remaining variables are saved in the same sequence as they appear in the original file.