BookmarkSubscribeRSS Feed
sas_student1
Quartz | Level 8


Hello Great SAS community experts!!

 

I have a dataset with hospital admissions and discharges by different service levels. I am trying to answer multiple questions with this dataset and am hoping that the great minds here can help me code efficiently and smartly.

 

First the questions: There are many questions I would like to be able to answer, but I will start with two. 1) how many unique people who have an inpatient (service=IN) discharge are admitted to an outpatient (service=OU) within in 30 days of the inpatient discharge I would like to know this by each hospital as well as overall. So if a patient visited Hospital A and was admitted and discharged under both the cateogries in hospital A I would give credit to hospital A. Also if a client was discharged from inpatient from Hospital F but had their admission at hospital G I would give Hospital F the credit. The other question (2) would be how many people had multiple inpatient discharge and outpatient admissions again looking at it both ways, within the same hospital and overall.

 

Here is the date set example. following this I have an example of what I think the final dataset would look like. But I am open to ideas.

 

data have;
  length Hosp $1. ID $3. service $2. ;
  input Hosp ID service admission :mmddyy10. discharge :mmddyy10.;
  format admission mmddyy10. discharge mmddyy10.;

datalines;
A 123 IN 01/01/2019 01/05/2019
A 123 ER 04/01/2019 04/03/2019
A 123 OU 06/05/2019 06/30/2019
A 123 OU 08/01/2019 08/29/2019
A 123 ER 09/01/2019 09/05/2019
A 123 IN 10/01/2019 10/05/2019
A 456 IN 01/05/2019 01/15/2019
A 456 OU 01/25/2019 01/30/2019
A 456 IN 02/05/2019 02/15/2019
A 456 ER 02/16/2018 02/18/2019
B 234 IN 01/01/2019 01/05/2019
B 234 ER 04/01/2019 04/03/2019
B 234 IN 06/05/2019 06/30/2019
B 234 IN 08/01/2019 08/29/2019
B 234 OU 09/01/2019 09/05/2019
B 234 IN 10/01/2019 10/05/2019
B 345 IN 10/01/2019 10/05/2019
B 345 OU 12/15/2019 12/16/2019
C 567 IN 02/03/2019 02/05/2019
C 567 ER 02/07/2019 02/15/2019
C 567 OU 02/20/2019 03/01/2019
C 567 OU 03/06/2019 03/10/2019
D 567 IN 04/01/2019 04/03/2019
D 567 OU 04/15/2019 04/16/2019
E 789 OU 05/01/2019 05/15/2019
E 789 IN 07/01/2019 07/15/2019
E 789 OU 08/01/2019 08/13/2019
F 234 IN 04/05/2019 04/15/2019
F 234 ER 01/25/2019 01/30/2019
G 234 OU 04/30/2019 05/01/2019
;
run;

I would think that maybe if we can get to the table below, where I have a flag for an inpatient row that has the 30 days outpatient visit, and then another indicator that would flag the 30 day outpatient. That way I may be able to run a sql program including the indicators to answer the above 2 questions within the hospital and overall, right?

 

 

HOSPIDServiceadmissiondischargeinpatient with 30 day outpatientthe 30 day outpatient
A123IN1/1/20191/5/201900
A123ER4/1/20194/3/201900
A123OU6/5/20196/30/201900
A123OU8/1/20198/29/201900
A123ER9/1/20199/5/201900
A123IN10/1/201910/5/201900
A456IN1/5/20191/15/201910
A456OU1/25/20191/30/201901
A456IN2/5/20192/15/201900
A456ER2/16/20182/18/201900
B234IN1/1/20191/5/201900
B234ER4/1/20194/3/201900
B234IN6/5/20196/30/201900
B234IN8/1/20198/29/201910
B234OU9/1/20199/5/201901
B234IN10/1/201910/5/201900
B345IN10/1/201910/5/201910
B345OU10/15/201910/16/201901
C567IN2/3/20192/5/201910
C567ER2/7/20192/15/201900
C567OU2/20/20193/1/201901
C567OU3/6/20193/10/201900
D567IN4/1/20194/3/201910
D567OU4/15/20194/16/201901
E789OU5/1/20195/15/201900
E789IN7/1/20197/15/201910
E789OU8/1/20198/13/201901
F234IN4/5/20194/15/201910
F234ER1/25/20191/30/201900
G234OU4/30/20195/1/201901

 

@mkeintz 

1 REPLY 1
s_lassen
Meteorite | Level 14

To me it seems that you can get the answers you want directly in SQL. 

 

You may want to start with finding all the valid combinations of discharge from IN and admission to OUT:

proc sql;
  create table all_in2out as select
     in.id,in.hosp as in_hosp,in.admission as in_adm, in.discharge as in_disc,
     out.hosp as out_hosp, out.admission as out_adm, out.discharge as out_disc
     from have in join have out 
       on in.id=out.id and
            out.admission between in.discharge and in.discharge+30 and
            in.service='IN' and 
            out.service='OU'
     ;
quit;

It should then be easy to find the answers to your questions, like 

how many unique people who have an inpatient (service=IN) discharge are admitted to an outpatient (service=OU) within in 30 days of the inpatient discharge

select count(distinct id) from all_in2out;

I would like to know this by each hospital as well as overall.

select in_hosp,count(distinct id) from all_in2out 
  group by in_hosp;

how many people had multiple inpatient discharge and outpatient admissions

select count(*) from 
  (select distinct id from all_in2out 
   group by id
   having count(*)>1);

 

Just be aware that real-life data do not always come as clean as your example - there may be cases where a patient has been discharged from IN and the admitted to more than one OU placement within the same 30 days. And even if you could solve that by only including the first OU admission in the ALL_IN2OUT table, you may still get the problem that a patient was admitted to two different OU records on the same day. So you should take some time to study the real-life data and look for such problems.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 1 reply
  • 334 views
  • 0 likes
  • 2 in conversation