KEEP= Data Set Option

For an input data set, specifies the variables to process; for an output data set, specifies the variables to write to the data set.
Valid in: DATA step and PROC steps
Category: Variable Control

Syntax

KEEP=variable-1 <...variable-n>

Syntax Description

variable-1 <...variable-n>
lists one or more variable names. You can list the variables in any form that SAS allows.

Details

If the KEEP= data set option is associated with an input data set, only those variables that are listed after the KEEP= data set option are available for processing. If the KEEP= data set option is associated with an output data set, only the variables listed after the option are written to the output data set. All variables are available for processing.

Comparisons

  • The KEEP= data set option differs from the KEEP statement in the following ways:
    • In DATA steps, the KEEP= data set option can apply to both input and output data sets. The KEEP statement applies only to output data sets.
    • In DATA steps, when you create multiple output data sets, use the KEEP= data set option to write different variables to different data sets. The KEEP statement applies to all output data sets.
    • In PROC steps, you can use only the KEEP= data set option, not the KEEP statement.
  • The DROP= data set option specifies variables to omit during processing or to omit from the output data set.

Example

In this example, only IDNUM and SALARY are read from PAYROLL, and they are the only variables in PAYROLL that are available for processing:
data bonus;
   set payroll(keep=idnum salary);
   bonus=salary*1.1;
run;

See Also

Data Set Options:
Statements:
KEEP Statement in SAS Statements: Reference