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

Syntax Description

variable(s)

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 that are 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 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, use only the KEEP= data set option, not the KEEP statement.

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