SAS OnlineTutor HomeFAQ PageSuggested Learning PathsContents+Searchback||next

Merging SAS Data Sets
Excluding Unmatched Observations


Creating Temporary IN= Variables

For example, suppose you want to match-merge the data sets Clinic.Demog and Clinic.Visit and select only observations that appear in both data sets.

First, you use IN= to create two temporary variables, InDemog and InVisit. The IN= variable is a temporary variable that is available to program statements during the DATA step, but it is not included in the SAS data set that is being created.


General form, IN= data set option:
(IN=variable)  

where

  • the IN= option, in parentheses, follows the data set name
  • variable names the variable to be created.

Within the DATA step, the value of the variable is 1 if the data set contributed data to the current observation, and 0 otherwise.


The DATA step containing the IN= options appears below. The first IN= creates the temporary variable InDemog, which is set to 1 when an observation from Clinic.Demog contributes to the current observation; otherwise, it is set to 0. Likewise, the value of InVisit depends on whether Clinic.Visit contributes to an observation or not.

 
     data clinic.combined;       
        merge clinic.demog(in=indemog) 
              clinic.visit(in=invisit  
                           rename=(date=BirthDate)); 
        by id;
     run;

 

NOTE: When you specify multiple data set options for a given data set, enclose them in a single set of parentheses.



back||next


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

Terms of Use & Legal Information | Privacy Statement