BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

Here is many to mane merge .

I need to get 9 rows but I get 5

How can I get the desired result please?

Data have1;
input AccountID trasactionKey;
cards;
123 222777
123 999999
456 333888
;
Run;


 Data have2;
 Input AccountID customerID;
 cards;
123 999
123 888
123 333 
123 222
456 333
;
Run;

Data wanted;
input AccountID trasactionKey customerID;
cards;
123 222777 999
123 222777 888
123 222777 333
123 222777 222
123 999999 999
123 999999 888
123 999999 333
123 999999 222
456 333888 333
;
Run;


proc sort data=have1;
by AccountID;
Run;

proc sort data=have2;
by AccountID;
Run;


Data My_Try_to_get_wanted;
merge have1(in=a) have2(in=b);
by AccountID;
if a;
Run;
3 REPLIES 3
andreas_lds
Jade | Level 19

Please have a look at the documentation of the merge statement, there you will find an explanation.

AndreaVianello
Obsidian | Level 7
Data have1;
input AccountID trasactionKey;
cards;
123 222777
123 999999
456 333888
;
Run;


 Data have2;
 Input AccountID customerID;
 cards;
123 999
123 888
123 333 
123 222
456 333
;
Run;

/**** sql full join ****/
proc sql; create table Want as select * from have1 full join have2 on have1.AccountID=have2.AccountID; quit;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 1092 views
  • 4 likes
  • 4 in conversation