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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 607 views
  • 4 likes
  • 4 in conversation