BookmarkSubscribeRSS Feed
mrafael03
Obsidian | Level 7

Hello,

I'll start by providing the requirement

  • Blue highlighted dates are the expected results
  • DAYS_DIFF=1st DISCH_DT-NEXT ADMIT_DT

1. If the discharge date is followed by readmission or direct transfer to an inpatient care setting within 30-day follow-up period, count only the last discharge date.

e.g.

ID     ADMIT_DT   DISCH_DT   DAYS_DIFF

011    1/10/2018       1/13/2018         16      <<< "readmission within 30 days - only include last discharge"

011    1/29/2018       2/28/2018

022    2/13/2018        2/17/2018        55      <<< "readmission >30 days"
022    4/13/2018        4/25/2018

 

2. For member with same admission date, but different discharge dates; use the last discharge date.

e.g.

ID    ADMIT_DT   DISCH_DT 

033   5/11/2018     5/12/2018
033   5/11/2018     5/17/2018   

 

3. For member with same discharge date, but different admit date; use the first admit date.

e.g.

ID    ADMIT_DT   DISCH_DT 

033  6/11/2018     6/17/2018
033  6/13/2018     6/17/2018

 

4. For member with the same 1st discharge date and next admit date, count the 1st admit and next discharge date.

e.g.

ID     ADMIT_DT   DISCH_DT  DAYS_DIFF

033  08/11/2018    08/17/2018        0
033  08/17/2018     08/23/2018

 

I would like to loop through the dataset by using RETAIN STATEMENT. See my codes below --- I'm still a newbie in SAS and trying to figure out how to retain the dates based on the criteria.  Any help would be greatly appreciated. Thank you!

 

EXPECTED RESULT:

IDADMIT_DTDISCH_DT
011    1/29/2018 2/28/2018
0222/13/2018  2/17/2018  
0224/13/2018 4/25/2018
0335/11/2018 5/17/2018
0336/11/20186/17/2018
03308/11/201808/23/2018

 

 

DATA DATASET1;
INPUT ID $1-3 ADMIT_DT 4-12 DISCH_DT 13-21;
DATALINES;
011 20180110 20180113
011 20180129 20180228
022 20180213 20180217
022 20180413 20180425
033 20180511 20180512
033 20180511 20180517
033 20180611 20180617
033 20180613 20180617
033 20180811 20180817
033 20180817 20180823
;
RUN;

DATA DATASET2;
SET DATASET1;
ADMIT_DT=INPUT(PUT(ADMIT_DT,8.),YYMMDD8.);
DISCH_DT=INPUT(PUT(DISCH_DT,8.),YYMMDD8.);
FORMAT ADMIT_DT DISCH_DT MMDDYY10.;
RUN;

PROC SORT DATA=DATASET2;
BY ID ADMIT_DT DISCH_DT;
RUN;


DATA RESULT;
SET DATASET2;
DAYGAP=0;
RETAIN STRT_DT END_DT;
FORMAT STRT_DT END_DT MMDDYY10.; 
BY ;
IF FIRST.ID THEN 
     DO;
     STRT_DT=ADMIT_DT;
     END_DT=DISCH_DT;
END;
     ELSE IF INTCK('DAY',END_DT,ADMIT_DT) <=30 AND STRT_DT>ADMIT_DT
     THEN DO;
     DAYGAP=INTCK('DAY',END_DT,ADMIT_DT);    
     END_DT=DISCH_DT;
	 END;

	 ELSE IF INTCK('DAY',END_DT,ADMIT_DT) >30
     THEN DO;
     DAYGAP=INTCK('DAY',END_DT,ADMIT_DT);
     STRT_DT=ADMIT_DT; 
     END_DT=DISCH_DT;
     END;

     ELSE DO;
     DAYGAP=INTCK('DAY',END_DT,ADMIT_DT);
     STRT_DT=ADMIT_DT;
     END_DT=DISCH_DT;
END;
/*DROP ADMS_DT DISCH_DT DAYGAP;*/
/*IF LAST.SBSCR_ID;*/
RUN;

 

 

2 REPLIES 2
mrafael03
Obsidian | Level 7
Good catch!!! Yes that’s correct, it should be removed as the next re-admission was within 30 days.

I meant to give an example for members with the same discharge date, only include 1st admit date and last discharge date.

Thanks for pointing out

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2 replies
  • 516 views
  • 1 like
  • 2 in conversation