data want;
merge dm(in=a) ae(in=b) cm(in=d) mh(in=d);
by usubjid;
if a and (b or c or d);
run;
Stay with your data step.
SQL (untested) might look like this:
proc sql;
create table want as
select
dm.*,
ae.aeterm,
cm.cmtrt,
mh.mhterm
from dm a
left join ae
on dm.usubjid = ae.usubjid
left join cm
on dm.usubjid = cm.usubjid
left join mh
on dm.usibjid = mh.usubjid
where a.usubjid in (
select distinct usubjid from ae
union
select distinct usubjid from cm
union
select distinct usubjid from mh
)
;
quit;
But I can only repeat the last line of my previous post. Compare the codes, and you'll see that forcing this unto SQL is just pure idiocy.
Try
proc sql;
select a.*
from dm a
where a.usubjid in (
select distinct usubjid from ae
union
select distinct usubjid from cm
union
select distinct usubjid from mh
);
quit;
If you need to include additional variables from datasets ae, cm and mh, the whole thing will be a lot more complicated.
The sheer simplicity of the data step code tells you which is the right tool for this task (Maxim 14),
Stay with your data step.
SQL (untested) might look like this:
proc sql;
create table want as
select
dm.*,
ae.aeterm,
cm.cmtrt,
mh.mhterm
from dm a
left join ae
on dm.usubjid = ae.usubjid
left join cm
on dm.usubjid = cm.usubjid
left join mh
on dm.usibjid = mh.usubjid
where a.usubjid in (
select distinct usubjid from ae
union
select distinct usubjid from cm
union
select distinct usubjid from mh
)
;
quit;
But I can only repeat the last line of my previous post. Compare the codes, and you'll see that forcing this unto SQL is just pure idiocy.
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.