I have a exposure date and start of adverse events date. I want to find the last exposure or same day exposure for each adverse event date.
Exposure date data
Subj exposure_date
A 2015-09-10
A 2015-10-01
A 2015-11-12
A 2015-11-25
Adverse event date data
Subj adverse_event_date
A 2015-09-23
A 2015-09-23
A 2015-10-16
A 2015-10-16
A 2015-11-05
A 2015-11-05
Desired data set
Subj Last_exposure_date
A 2015-09-10
A 2015-09-10
A 2015-10-01
A 2015-10-01
A 2015-10-01
A 2015-10-01
Hi,
Well, not typing test data in so this is an untested shell:
proc sql;
select AE.*,
(select max(EXPOSURE_DATE) from EX where SUBJ=AE.SUBJ and EXPOSURE_DATE <= AE.ADVERSE EVENT_DATE) as EXPOSURE_DATE
from AE AE;
quit;
Hi,
Well, not typing test data in so this is an untested shell:
proc sql;
select AE.*,
(select max(EXPOSURE_DATE) from EX where SUBJ=AE.SUBJ and EXPOSURE_DATE <= AE.ADVERSE EVENT_DATE) as EXPOSURE_DATE
from AE AE;
quit;
@RW9 I have one more question. If EX data set has one more variable, how can I add it to resulting data set? I tried to put it as the separate subquery as you did, it is not working.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.