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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 710 views
  • 1 like
  • 2 in conversation