DROP and KEEP subcommands (SAVE DATA COLLECTION 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 on DROP does not affect the order of variables in the data file.
  • Keyword ALL on KEEP refers to all remaining variables that were not previously specified on KEEP or DROP. 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. If a variable is specified that is not in the active dataset or that has been dropped because of a previous DROP or KEEP subcommand, an error results, and the SAVE DATA COLLECTION command is not executed.
  • Keyword TO can be used to specify a group of consecutive variables in the active file.
  • If the active dataset was created from a IBM® SPSS® Data Collection data source, any original variables defined as grid or array elements in the IBM SPSS Data Collection data source are retained in the metadata file, even if those variables are not included in the IBM SPSS Statistics data file. Thus, the original grid or array structure is preserved, but there will be no case data for any variables not included in the IBM SPSS Statistics data file.

Example

SAVE DATA COLLECTION
  /OUTFILE='/data/survey.sav'
  /METADATA='/data/survey.mdd'
  /DROP gridVar7
  /KEEP gridVar1 to gridVar8.

Assuming that the order of the variables in the active dataset is gridVar1, gridVar2, gridVar3,...gridVar8 and that all eight variables are grid variables in the original IBM SPSS Data Collection data source, gridVar7 will be dropped from survey.sav, but the original metadata for gridVar7 will be preserved in survey.mdd.