DROP and KEEP Subcommands (GET command)

DROP and KEEP are used to copy a subset of variables into the active dataset. DROP specifies variables that should not be copied into the active dataset. KEEP specifies variables that should be copied. Variables not specified on KEEP are dropped.

  • Variables can be specified in any order. The order of variables on KEEP determines the order of variables in the active dataset. The order of variables on DROP does not affect the order of variables in the active dataset.
  • The 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. However, specifying a variable named on a previous DROP or not named on a previous KEEP results in an error, and the GET command is not executed.
  • The keyword TO can be used to specify a group of consecutive variables in the data file.

Example

GET FILE='/data/hubtemp.sav'   /DROP=DEPT79 TO DEPT84 SALARY79.
  • All variables between and including DEPT79 and DEPT84, as well as SALARY79, are excluded from the active dataset. All other variables are included in the active dataset.
  • Variables in the active dataset are in the same order as the variables in the original file.

Example

GET FILE='/data/prsnl.sav' /DROP=GRADE STORE 
               /KEEP=LNAME NAME TENURE JTENURE ALL.
  • The variables GRADE and STORE are dropped when the file prsnl.sav is copied into the active dataset.
  • KEEP specifies that LNAME, NAME, TENURE, and JTENURE are the first four variables in the active dataset, followed by all remaining variables (except those dropped by the previous DROP subcommand). These remaining variables are copied into the active dataset in the same sequence in which they appear in the prsnl.sav file.