BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
dapenDaniel
Obsidian | Level 7

Hi SAS Masters,

 

I have two dataset. Have1 has 293 observations and Have2 has 246 observations. Both of them only have one variable called "base". I am wondering how many of them are shown in both datasets. I have sorted these two datasets by base. The code I used is below.

 

data common;
merge have1(in=h1) have2(in=h2);
by base;
if h1 and h2 then output common;
run;

however, the number of observations in "Common" is 258, which is more than the number of observations in Have2 (258 > 246). Did I use the wrong code? Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hi @dapenDaniel  That means one of the datasets has duplicate values of the same causing one to many join

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

Hi @dapenDaniel  That means one of the datasets has duplicate values of the same causing one to many join

novinosrin
Tourmaline | Level 20

Consider this example to help you understand better

 

data one;
input var;
cards;
1
2
3
;

data two;
input var;
cards;
1
1
2
2
2
3
;

data want;
 merge one two;
 by var;
run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 441 views
  • 0 likes
  • 2 in conversation