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;
Please have a look at the documentation of the merge statement, there you will find an explanation.
9 observations points to a cartesian join, for which you need PROC SQL.
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.