BookmarkSubscribeRSS Feed
sasbasls
Calcite | Level 5
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
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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.
SPR
Quartz | Level 8 SPR
Quartz | Level 8
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

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
  • 2 replies
  • 983 views
  • 0 likes
  • 3 in conversation