Starting with the code from @Tom and adding some stuff. Should work dynamically. data have;
input id $ Startdate1 Enddate1 Startdate2 Enddate2;
informat s: e: date.;
format s: e: yymmdd10.;
cards;
1 1-Jan-92 31-Mar-92 1-Aug-99 30-Sep-12
2 1-Apr-93 31-Dec-99 . .
;
run;
data want;
set have;
array enrolled [312];
array startDate [2]; *Set to the correct number, how many possible start and end dates are there?;
array endDate [2]; *Set to the correct number, how many possible start and end dates are there?;
*Init all the enroll variables to 0 first.;
do _i=1 to dim(enrolled);
enrolled[_i]=0;
end;
*Loop the startDate array. Assuming that all the start dates has an end date.;
do _j=1 to dim(startDate);
_startIndex=intck('month','01dec1990'd,startDate[_j]);
_endIndex=intck('month','01dec1990'd,endDate[_j]);
if _startIndex ne . then do; *Dont want to try to use start dates that are missing.;
do _k=_startIndex to _endIndex;
enrolled[_k]=1;
end;
end;
end;
drop _:;
run;
... View more