Specifies the variables to include in output SAS data sets.
| Valid in: | DATA step |
|---|---|
| Categories: | CAS |
| Information | |
| Type: | Declarative |
Table of Contents
specifies the names of the variables to write to the output data set.
| Tip | 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.
If the same variable is listed on both the DROP and KEEP statements, DROP takes precedence over KEEP regardless of the order of the statements, and the variable is dropped.
These examples show the correct syntax for listing variables in the KEEP statement.
keep name address city state zip phone;
keep rep1-rep5;
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 set AVERAGE.
data average;
keep name avg;
infile file-specification;
input name $ score1-score20;
avg=mean(of score1-score20);
run;