BookmarkSubscribeRSS Feed
Sam_I_am
Calcite | Level 5

I have a dataset that looks similar to this

MemberID   StartDate1   EndDate1    Startdate2     Enddate2 StartDate3 EndDate3...StartDate20 Enddate20 

 XXXXXX     01Jun2013  30Jul2015 

 XXXXXX     01Aug2015 31Dec2016   01Feb2017    01Sep2017

 XXXXXX     15Jan2012  15Dec2017

 XXXXXX     01Jan2014  01May2014  15June2014  15Aug2016

 

I have to determine 6 months of continuous enrollment with an allowable gap of 45 days during a two year measure period, lets say Jan 01 2015-Dec 31, 2017. There is no anchor date. So essentially, I want to check all enrollment dates between Jan 01 2015 and December 31st 2017 and see if they have at least 6 months of continuous enrollment. I'm not sure how to approach this when there are multiple start and end dates. Does anyone have any suggestions?

2 REPLIES 2
Reeza
Super User

Post some more example data and the corresponding expected output. 

If you search on here, it's been answered multiple times, but with a different data structure, a long rather than wide data set.

s_lassen
Meteorite | Level 14

Something like this may work (not tested):

data want;
  set have;
  array startdates startdate1-startdate20;
  array enddates enddate1-enddate20;
enrolled=0; do _N_=1 to dim(startdates); /* find first enrollment within interval */
if '01jan2015'd<=enddates(_N_)<='31dec2017'd or
'01jan2015'd<=startdates(_N_)<='31dec2017'd
then do; enroll_from=max(startdates(_N_),'01jan2015'd);
enroll_to=min(enddates(_N_),'31dec2017'd);
enrolled=intck('month',enroll_from,enroll_to,'C')>=6;
leave;
end;
end;
do _N_=_N_+1 to dim(startdates) while(not enrolled);
if startdates(_N_)>'31dec20017'd then
leave;
if startdates(_N_)-enroll_to>45 then
enroll_from=startdates(_N_);
    enroll_to=min(enddates(_N_),'31dec2017'd);
   enrolled=intck('month',enroll_from,enroll_to,'C')>=6;
end;
drop enroll_from enroll_to;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 2 replies
  • 1700 views
  • 0 likes
  • 3 in conversation