Statements |
Valid: | in a DATA step |
Category: | Information |
Type: | Declarative |
Syntax | |
Arguments | |
Details | |
Comparisons | |
Examples | |
See Also |
Syntax |
KEEP variable-list; |
specifies the names of the variables to write to the output data set.
Tip: | List the variables in any form that SAS allows. |
Details |
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.
Comparisons |
The KEEP 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 selects observations.
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.
Examples |
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 set AVERAGE.
data average; keep name avg; infile file-specification; input name $ score1-score20; avg=mean(of score1-score20); run;
See Also |
| |||||||
|
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.