Specifies the variables to include in output SAS data
||in a DATA step
specifies the names of the variables to
write to the output data set.
List the variables in any
form that SAS allows.
The KEEP statement causes a DATA step
to write only the variables that you specify to one or more SAS data sets.
The KEEP statement applies to all SAS data sets that are created within the
same DATA step and can appear anywhere in the step. If no KEEP or DROP statement
appears, all data sets that are created in the DATA step contain all variables.
Note: Do not use both the KEEP and DROP statements
within the same DATA step.
statement cannot be used
in SAS PROC steps. The KEEP= data set option can.
The KEEP statement applies to all
output data sets that are named in the DATA statement. To write different
variables to different data sets, you must use the KEEP= data set option.
The DROP statement is a parallel statement that
specifies variables to omit from the output data set.
The KEEP and DROP statements select variables
to include in or exclude from output data sets. The subsetting IF statement
Do not confuse the KEEP statement with the RETAIN
statement. The RETAIN statement causes SAS to hold the value of a variable
from one iteration of the DATA step to the next iteration. The KEEP statement
does not affect the value of variables but only specifies which variables
to include in any output data sets.
These examples show the correct syntax for listing
variables in the KEEP statement:
This example uses the KEEP statement to include
only the variables NAME and AVG in the output data set. The variables SCORE1
through SCORE20, from which AVG is calculated, are not written to the data
keep name avg;
input name $ score1-score20;
Data Set Option:
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.