DATA Step, Macro, Functions and more

Please help with merge step

Reply
Contributor
Posts: 40

Please help with merge step

There are two data sets - Member and Sorted

for all records in data set b (variables different from data set a, but there is one mrgvar ) , I need to catenate matching record info from data set a on that merge variable.

Below logic is not writing out any of info -


DATA Merged;
MERGE MEMBER(in=a) sorted(in=b);
BY MRGVAR1 ;
if a and b ;
RUN;

Also this below is writing only info from data set b , but not from data set a.

DATA Merged;
MERGE MEMBER(in=a) sorted(in=b);
BY MRGVAR1 ;
if b ;
RUN;


How to accomplish all member info catenated with sorted info for a matching merge variable.

thanks,
ls
Super Contributor
Super Contributor
Posts: 3,174

Re: Please help with merge step

From what you have explained, it appears as though you do not actually have a common SAS variable to use with the MERGE/BY processing.

You need to investigate your input data files for differences for your MERGE/BY variable(s).

And, you can add this SAS statement to help diagnose the IN= variable when doing the MERGE -- though, again, it will not solve any problem.

PUTLOG _ALL_;

Possibly using PROC FREQ may help analyze your input file(s), as well.

Scott Barry
SBBWorks, Inc.
Super Contributor
Super Contributor
Posts: 365

Re: Please help with merge step

Hello SASBasis,

It seems to me that you need proc SQL:
[pre]proc SQL;
create table Merged as
select a.*, b.*
from Member as a left join Sorted as b
where a.MRGVAR1=b.MRGVAR1
;quit;
[/pre]
The only thing I'd like to note. Instead of my b.* it is better to list all necessary fields from Sorted (e.g. if Sorted contains fields MRGVAR1, A, B, etc. then it should be b.A, b.B etc. MRGVAR1 it is not necessary to list).
Sincerely,
SPR
Ask a Question
Discussion stats
  • 2 replies
  • 118 views
  • 0 likes
  • 3 in conversation