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;
... View more