DATA Step, Macro, Functions and more

Proc SQL linking on dates 1 day apart?

Accepted Solution Solved
Reply
Regular Contributor
Posts: 164
Accepted Solution

Proc SQL linking on dates 1 day apart?

Hello

 

I am using SAS 9.3.

 

I have inpatient and outpatient data.  I want to link the Emergency Room abstract with the inpatient one for those admitted via the ER.  However, the admit date of the inpatient visit could be a day later than the end date of the ER abstract.  Is there any way to do this?

 

The ED table only has those visits admitted and the inpatient cases only have those admitted via the ED.  The current resulting dataset is missing out on those where the ED end date is a day later i.e. the inpatient admit date is April 10, 2017 and the ED end date is April 11, 2017. 

 

My current code:

proc sql;
create table Links as select
a.HCN,
a.alias,
a.admdate,
b.regdate,
b.triage
from inpatients as a
left join ED as b
on a.HCN = b.HCN 
and b.enddate<=a.admdate<=b.enddate+1;

Any and all assistance greatly appreciated.

 


Accepted Solutions
Solution
‎09-16-2017 01:53 PM
Respected Advisor
Posts: 4,927

Re: Proc SQL linking on dates 1 day apart?

Try the join condition

 

on a.HCN = b.HCN
and a.admdate between b.enddate and b.enddate+1

PG

View solution in original post


All Replies
Solution
‎09-16-2017 01:53 PM
Respected Advisor
Posts: 4,927

Re: Proc SQL linking on dates 1 day apart?

Try the join condition

 

on a.HCN = b.HCN
and a.admdate between b.enddate and b.enddate+1

PG
Super User
Posts: 19,822

Re: Proc SQL linking on dates 1 day apart?

Is it a date or date time variable? I thought it was usually DT. It's also really rare but it can be longer than a day. 

Regular Contributor
Posts: 164

Re: Proc SQL linking on dates 1 day apart?

Thanks to you both for responding.  I worked on it last night and I created a new field called "d_date" that was the +1 and added as an OR statement.  So PGStats response but instead of using "+1" I built that as a field elsewhere. 

 

Thanks so much!

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 262 views
  • 0 likes
  • 3 in conversation