SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Reading and Concatenating SAS Data Sets
Selecting Variables


Where to Specify DROP= and KEEP=

You can specify DROP= and KEEP= anywhere you name a SAS data set. When concatenating, you can specify these options in either the DATA statement or the SET statement, depending on whether or not you want to process values of the variables in that DATA step:

  • 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 that is 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; 
Used in the DATA statement, the DROP= option simply drops the variables from the new data set. However, they are still read from the original data set and are available within the DATA step.

back||next


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

Terms of Use & Legal Information | Privacy Statement