Hello,
I'll start by providing the requirement
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/2018033 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 0033 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:
ID | ADMIT_DT | DISCH_DT |
011 | 1/29/2018 | 2/28/2018 |
022 | 2/13/2018 | 2/17/2018 |
022 | 4/13/2018 | 4/25/2018 |
033 | 5/11/2018 | 5/17/2018 |
033 | 6/11/2018 | 6/17/2018 |
033 | 08/11/2018 | 08/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;
Per your rule, the first two observations of ID 33 (ADMIT_DT 2018-05-11) need to be removed, as the DISCH_DT is within 30 days of the next ADMIT_DT.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.