Selecting Variables

When you create a new data set, you can use options to drop or keep variables that are stored in the original data set. You name the variables you want to drop or keep by using the DROP= and KEEP= data set options.

You can use the KEEP= option instead of the DROP= option if more variables are dropped than kept. You specify data set options in parentheses after a SAS data set name.


General form, DROP= and KEEP= data set options:
(DROP=variable-1 < . . . variable-n>)
(KEEP=variable-1 < . . . variable-n>)

where

  • the DROP= or KEEP= option, in parentheses, follows the name of the data set containing the variables to be dropped or kept
  • variable is the name of one or more variables, separated by blanks.


You can specify DROP= and KEEP= anywhere you name a SAS data set:
  • If you don't process certain variables and you don't want them to appear in the new data set, specify them in the DROP= option in the SET statement.

    In the DATA step below, the DROP= option in the SET statement prevents the variables Triglycerides and UricAcid from being read. These variables won't appear in the Lab23.Drug1H data set.
     data lab23.drug1h(drop=placebo);
        set research.cltrials
            (drop=triglycerides uricacid);
        if placebo='YES';
     run; 

  • If you do need to process a variable in the original data set (in a subsetting IF statement, for example), you must specify the variable in the DROP= option in the DATA statement. Otherwise, the statement using the variable for processing causes an error.

    The DATA step uses the variable Placebo to select observations. To drop Placebo from the new data set, the DROP= option must appear in the DATA statement.
     data lab23.drug1h(drop=placebo);
        set research.cltrials
            (drop=triglycerides uricacid);
        if placebo='YES';
     run; 




Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement