BookmarkSubscribeRSS Feed
GregorClegane
Calcite | Level 5

So I have been thinking about this issue for a little bit and I am scratching my head at the best way to approach this issue.  I have 3 fields, I have Member, Discharge_DT and Service_DT.

 

I am trying to determine which service dates fall between 1 - 7 days between the Discharge_DT and Service_DT also

I am trying to determine which service dates fall between 1 - 30 days between the Discharge_DT and Service_DT.

 

I was thinking something along the lines of 

 

PROC SQL;

create table work.test as

select distinct

MEMBER,

DISCHARGE_DT,

(SERVICE_DT - DISCHARGE_DT) as days



from work.table

group by 1,2;

quit;

But I am not 100% on the syntax and I want to make sure I am grabbing everything based on the Discharge and not omitting anything. 

 

Thank you for your help

4 REPLIES 4
JeffMaggio
Obsidian | Level 7

How are the dates formatted?

If they are not dates, you'll have to use a conversion first.

 

Also, I don't know your data, but are you sure you don't want 

<span class="token punctuation">(DISCHARGE_DT - </span>SERVICE_DT<span class="token punctuation">)</span> as days

 instead? Is this some kind of length of stay for health data?

 

If you simply want to check / filter results. You could use something like:

where DISCHARGE_DT <= SERVICE_DT + 7

You don't have any summary columns in your example, so you would not want to include a group by clause.

GregorClegane
Calcite | Level 5

@JeffMaggio  Thank you, I am playing around with your code now to see what it looks like.  The dates are just in a date9. type format.  I was also reading up on the SAS Lag function, but I still haven't gotten my mind around that.

 

Thanks for the start, I will respond with good/bad news!

GregorClegane
Calcite | Level 5

@JeffMaggio I have been trying your logic you suggested and I still can't seem to wrap my head around how to make it work.  Here is a sample of my data, along with what I am expecting, I hope this clarifies some questions.

 

Member_IDDischarge_DateDiagnosisService_DateDiagnosis
000105JAN201942808JAN2019428
000128FEB201912304MAR2019922
000111JUN2019410  
000202AUG201923829AUG2019238
000201SEP2019210  
000204NOV201930812DEC2019242
000320DEC201910522DEC2019105
000401MAR201912404APR2019124
000530APR201918509MAY2019

252

 

So in this example I am looking to count the number of days between the discharge date and new service date.  However the following needs to match.  The member id needs to match along with the diagnosis code.  So I would want to end up with something like the following:

 

Member_IDDischarge_DateDiagnosisService_DateDiagnosisDay Count
000105JAN201942808JAN20194283
000202AUG201923829AUG201923827
000320DEC201910522DEC20191052
000401MAR201912404APR2019124

34

 

Once I have that Day Count field I can start to build my flags.  

 

Member_IDDischarge_DateDiagnosisService_DateDiagnosisDay CountFlag
000105JAN201942808JAN201942831-7
000105JAN201942808JAN201942831-30
000202AUG201923829AUG2019238271-7
000202AUG201923829AUG2019238271-30
000320DEC201910522DEC201910521-7
000320DEC201910522DEC201910521-30
000401MAR201912404APR201912434na

 

 

So with each flag, it will duplicate the data since the members should fall into each bucket.

 

 

Thank you again!

JeffMaggio
Obsidian | Level 7

Try something like this:

data have;
Member_ID='0001';	Discharge_Date='05JAN2019'd;	Diagnosis=428;	Service_Date='08JAN2019'd;	Diagnosis2=428; output;
Member_ID='0001';	Discharge_Date='28FEB2019'd;	Diagnosis=123;	Service_Date='04MAR2019'd;	Diagnosis2=922; output;
Member_ID='0001';	Discharge_Date='11JUN2019'd;	Diagnosis=410;	Service_Date=.;             Diagnosis2=.;	 output;
Member_ID='0002';	Discharge_Date='02AUG2019'd;	Diagnosis=238;	Service_Date='29AUG2019'd;	Diagnosis2=238; output;
Member_ID='0002';	Discharge_Date='01SEP2019'd;	Diagnosis=210;	Service_Date=.;             Diagnosis2=.;	 output;
Member_ID='0002';	Discharge_Date='04NOV2019'd;	Diagnosis=308;	Service_Date='12DEC2019'd;	Diagnosis2=242; output;
Member_ID='0003';	Discharge_Date='20DEC2019'd;	Diagnosis=105;	Service_Date='22DEC2019'd;	Diagnosis2=105; output;
Member_ID='0004';	Discharge_Date='01MAR2019'd;	Diagnosis=124;	Service_Date='04APR2019'd;	Diagnosis2=124; output;
Member_ID='0005';	Discharge_Date='30APR2019'd;	Diagnosis=185;	Service_Date='09MAY2019'd;	Diagnosis2=252; output;
format Discharge_Date date9. Service_Date date9.; 
run;

data lookup;
length Flag $8.;
Fstart = 1; Fend=7; Flag='1-7'; output;
Fstart = 1; Fend=30; Flag='1-30'; output;
run;

proc sql;
create table want as 
select
t1.*,
(t1.Service_Date - t1.Discharge_Date) as Day_Count,
case when (t1.Service_Date - t1.Discharge_Date) <= 30 then t2.Flag else 'na' end as Flag
from have t1
    left join lookup t2 on ( Fstart <= (t1.Service_Date - t1.Discharge_Date) <= Fend)
where Service_Date ne . 
having Diagnosis = Diagnosis2 and Diagnosis2 ne .
;
quit;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 4 replies
  • 453 views
  • 0 likes
  • 2 in conversation