BookmarkSubscribeRSS Feed
Ronein
Meteorite | Level 14

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;

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