BookmarkSubscribeRSS Feed
A_Swoosh
Quartz | Level 8

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

3 REPLIES 3
mkeintz
PROC Star
  1. What does 12/31/9999 mean?  Does start=01APR2018 with end=31DEC999 mean that time span overlaps with all date ranges after 01APR2018?  This would mean there can no gaps in that range.

  2. Which brings me to this question.  What is a gap?  The only way I can see the 30 day gap for PATID 1 that you mention is if I limit the consideration to records with PLAN=1.

    But if I apply the same rule to PATID 2 (looking for gaps with a given PLAN for PATID 2) I don't see the multiple 45 day gaps you cite.


  3. Which in turn makes me ask whether you intend to ignore records with PLAN=.
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
A_Swoosh
Quartz | Level 8

@mkeintz 

 

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).

A_Swoosh
Quartz | Level 8

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.&yend."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.&yend."d then service_end = EndDate;
				else service_end = "&mend.&yend."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.&yend."d then service_end = EndDate;
					else service_end = "&mend.&yend."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.&yend."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...

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 1465 views
  • 0 likes
  • 2 in conversation