Hi all,
I've seen other threads in the SAS programming community that address the issue of continuous enrollment with various lags. I wanted to present a more complex request involving additional variables aside from date.
I have a subset example of a sample dataset as follows:
data History;
input patid plan lob $ aid $ eligible start end;
informat start end mmddyy10.;
format start end date9.;
cards;
1 1 MC LIS 1 10/1/2019 12/31/9999
1 2 MC LIS 1 9/1/2019 9/30/2019
1 1 MC LIS 1 10/1/2018 08/31/2019
1 . FFS LIS 1 4/1/2018 12/31/9999
1 1 MC LIS 1 4/1/2018 9/30/2018
1 . FFS noLIS 0 8/1/2015 3/31/2018
1 1 MC noLIS 0 8/1/2015 3/31/2018
2 . FFS LIS 1 12/18/2019 12/31/9999
2 3 MC LIS 1 6/1/2019 12/17/2019
2 . FFS LIS 1 5/1/2019 12/31/9999
2 3 MC LIS 1 8/1/2018 4/30/2019
2 3 MC LIS 1 7/1/2018 7/31/2018
2 . FFS LIS 1 5/1/2018 4/30/2019
3 2 MC noLIS 0 8/1/2018 12/31/9999
3 2 MC noLIS 0 8/1/2017 7/31/2018
3 . FFS noLIS 0 5/1/2017 12/31/9999
3 . FFS noLIS 0 12/1/2012 4/30/2017
3 2 MC noLIS 0 12/1/2012 4/30/2017
;
run;
This dataset has:
1) patient id
2) Plan
3) Line of Business (e.g. Medicare FFS or Managed Care (MC)
4) Aid (LIS vs. noLIS)
5) Eligibility Criteria
6) Start Date
7) End Date
Want:
I want to create 2 datasets; continuously enrolled for the calendar year with no more than 1 gap of 45 days
By aid (LIS)--like a case vs control with the aid category being the identifier
Results:
Patient 1: Would fall into the case group; has only 1 gap of 30 days so it is included
Patient 2: Would be removed since they have 2 gaps in enrollment
Patient 3: Would fall into the control group; no gap and has noLIS
1. 9999 end date means it’s current and basically has no gaps. It extends beyond the measurement year.
2. A gap is continuously enrolled for the entire calendar year with no more than 1 gap of 45 days.
Edit: I corrected the instance for patient 2. They have 2 gaps; one from May to June and another from 12/17-12/31
3. Plan is only needed for this instance; The plan they begin the measurement year with (2019). Any breaks of more than 45 days (eg row 2 for patient 1) would be considered a gap. So for patient 1, they would be in the case group because their aid is LIS, they are eligible and they have 1 gap (row 2 equaling less than 45 days).
I'm not sure if I'm on the right track but this is what I have so far:
%let mstart = 01JAN;
%let mend = 31DEC;
%let ystart = 2019;
%let yend = 2019;
proc sort data = history out = cases (keep = patid LOB aid PLAN StartDate EndDate eligible);
by patid StartDate EndDate;
where EndDate > "&mstart.&ystart."d and StartDate < "&mend.¥d."d and LOB = "MC" and (intnx('year',DOB,18,'same')) > "&mstart.&ystart."d and eligible=1
run;
data cases_test;
retain gap_count last_start service_end service_began official_start official_end;
set cases;
by patid;
format last_start service_end service_began official_start official_end date9.;
if first.patidthen do;
if StartDate >= "&mstart.&ystart."d then service_began = StartDate;
else service_began = "&mstart.&ystart."d;
if EndDate <= "&mend.¥d."d then service_end = EndDate;
else service_end = "&mend.¥d."d;
if StartDate >= "&mstart.&ystart."d then last_start=StartDate;
else last_start = "&mstart.&ystart."d;
gap_count=0;
end;
else do;
if StartDate < service_began then do;
if StartDate >= "&mstart.&ystart."d then service_began = StartDate;
else service_began = "&mstart.&ystart."d;
end;
else service_began = service_began;
if EndDate > service_end then do;
if EndDate <= "&mend.¥d."d then service_end = EndDate;
else service_end = "&mend.¥d."d;
end;
else service_end=service_end;
if intck('day',EndDate,last_start) > 0 then gap_count=gap_count+(intck('day',EndDate,last_start)-1);
else gap_count=gap_count;
if StartDate >= "&mstart.&ystart."d then last_start=StartDate;
else last_start = "&mstart.&ystart."d;
end;
official_start="&mstart.&ystart."d;
official_end="&mend.¥d."d;
run;
I think from here I may be able to use a lag from the previous row then create gap variables to count the different gaps. Not sure if there is a better approach...
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.