Skip to content
Advertisement

Create Continuous Enrollment islands for a certain sub-population

My end goal is to create islands of continuous enrollment days for each CLIENTID for a single sub-population: ‘Adult Expansion’ for calendar years 2019 and 2020. A CLIENTID can be associated with multiple sub-populations in a calendar year, but can never be associated with more than one sub-population at once (there is no overlap in enrollment). My data go back to 2016, but I am only interested in 2019 and 2020. The data are structured that each row is a single enrollment period, with start and end dates of enrollment, associated with a sub-population.

I’ve included below some dummy data and a desired output to better illustrate my goal:

DESIRED OUTPUT:

CLIENTID AGE ELIGBEGIN ELIGEND Sequence_ID
123456789 52 2019-12-19 2019-12-31 1
123456789 52 2020-01-01 2020-01-15 2
123456789 52 2020-03-01 2020-12-31 3
012345678 52 2020-02-01 2020-28-20 1
012345678 52 2020-03-01 2020-03-31 2
020234587 36 2019-06-01 2019-06-30 1
020234587 36 2019-08-01 2019-11-30 2

Then here is the current code I am using to attempt and solve this problem.

However, the actual output of the final SELECT * FROM #testcase is the following:

ACTUAL RESULT:

CLIENTID AGE ELIGBEGIN ELIGEND Sequence_ID
123456789 52 2019-12-19 2019-12-31 1
123456789 52 2020-01-01 2020-01-15 2
123456789 52 2020-03-01 2020-12-31 3
020234587 36 2019-06-01 2019-06-30 1
020234587 36 2019-08-01 2019-11-30 2

As you can see there are three major issues I’m facing with the actual output not matching the desired output.

  1. I have to run the same query twice for two different years because I couldn’t figure out how to otherwise segment enrollment for a member with continuous enrollment from 2019-12-31 to 2020-01-31 and beyond. If I run the code table #t instead of table #y1, the first CLIENTID’s output would be 12/16/19 through 1/15/20, which I do not want.
  2. I entirely lose one CLIENTID because they were in the ‘Adult Expansion’ sub-population, then in the ‘Demonstration Population #3’, and back into the ‘Adult Expansion’
  3. For some reason, the code will properly ignore preceding rows where a client’s DEMONSTRATION_POPULATION != 'Adult Expansion' but if a CLIENTID changes from ‘Adult Expansion’ to a different sub-population, then the actual output still includes the enrollment dates from this different sub-population which is directly against my desired output. I only want the enrollment segments when an individual is enrolled in ‘Adult Expansion’.

If anyone can assist in solving for the three above problems, I would be super grateful!

Thanks, in advance, for any tips!

Advertisement

Answer

Here’s a solution using a gaps-and-islands approach:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement