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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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