DATA Step, Macro, Functions and more

date time issue

Accepted Solution Solved
Reply
Super Contributor
Posts: 271
Accepted Solution

date time issue

[ Edited ]

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

 

 

 


Accepted Solutions
Solution
‎04-26-2016 04:41 PM
Super User
Super User
Posts: 7,942

Re: date time issue

Posted in reply to SAS_inquisitive

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;

View solution in original post


All Replies
Solution
‎04-26-2016 04:41 PM
Super User
Super User
Posts: 7,942

Re: date time issue

Posted in reply to SAS_inquisitive

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;
Super Contributor
Posts: 271

Re: date time issue

@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.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 184 views
  • 0 likes
  • 2 in conversation