KEEP Statement


Includes variables in output SAS data sets

Valid: in a DATA step

Category: Information

Type: Declarative

Syntax

KEEP variable-list ;

Arguments

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:

    •  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; 

See Also

Data Set Option:

  • KEEP= Data Set Option on page 30

Statements:

  • DROP Statement on page 1150

  • IF Statement, Subsetting on page 1212

  • RETAIN Statement on page 1381




SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 704

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net