BookmarkSubscribeRSS Feed
HeatherNewton
Quartz | Level 8
data seta;
input apple banana;
datalines;
1 1
2 2
3 3
run;

proc sort data=seta;
by apple;
run;

data setb;
input apple orange lemon pear;
datalines;
11 11 11 11
22 22 22 22
1  2 3 4 
run;

proc sort data=setb;
by apple;
run;

data outina;
merge seta (in=a) setb;
by apple;
run;

data outnoth;
merge seta setb;
by apple;
run;

proc print data=seta;
run;

proc print data=setb;
run;

proc print data=outina;
run;

proc print data=outnoth;
run;

I am getting exact same result for with or without (in=a), why?

I was believing (in=a) is like a left join... where only observations  with apple =1,2,3 would be included...

 

 

 

 

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

@HeatherNewton Good question.

 

The IN= Data Set Option "Creates a Boolean variable that indicates whether the data set contributed data to the current observation." (Straight from the documentation). So in your example, the in=a data set option creates a 0/1 variable (automatically dropped). You can assign the value to another variable to see it in your output like below. 

 

data outina;
merge seta (in=a) setb;
by apple;
ina = a; run;

 

Result:

 

apple banana orange lemon pear ina
1     1      2      3     4    1
2     2      .      .     .    1
3     3      .      .     .    1
11    .      11     11    11   0
22    .      22     22    22   0

 

Therefore, to replicate an SQL Left Join, you should use a Subsetting If Statement like below to output only the observations where the seta data set contributes.

 

data outina;
merge seta (in=a) setb;
by apple;
if a;
run;

 

Result:

 

apple banana orange lemon pear 
1     1      2      3     4    
2     2      .      .     .    
3     3      .      .     .    

 

PeterClemmensen
Tourmaline | Level 20

@HeatherNewton , did this answer your question?

HeatherNewton
Quartz | Level 8

yes thx

PeterClemmensen
Tourmaline | Level 20

Good. Please remember to close the thread 🙂

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 668 views
  • 1 like
  • 2 in conversation