KEEP= Data Set Option

For an input data set, specifies the columns to process; for an output data set, specifies the columns to write to the data set.

Valid in: DATA and PROC steps
Category: Variable Control
Supports: All

Syntax

Syntax Description

column(s)

lists one or more column names. You can list the columns in any form that SAS allows.

Details

When the KEEP= data set option is associated with an input data set, only those columns that are listed after the KEEP= data set option are available for processing. When the KEEP= data set option is associated with an output data set, only the columns that are listed after the option are written to the output data set. However, all columns 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 columns 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 columns to omit during processing or to omit from the output data set.

Example: Limiting Columns in the SET Statement

In this example, only columns IdNum and Salary are read from Payroll, and they are the only columns in Payroll that are available for processing:
data myfiles.bonus;
   set myfiles.payroll (keep=idnum salary);
   bonus=salary*1.1;
run;
proc print data=myfiles.bonus(obs=2);
  title 'bonus data set';
run;