Here is an array solution with 4 month intervals.
data have;
input id @3 begin_date date9.
@13 final_date_new date9.;
datalines;
1 11jun2010 23aug2011
2 30nov2009 30nov2012
3 30nov2009 30nov2016
run;
data want(drop=int);
set have;
array strtdate {8} intstart1 - intstart8;
array stopdate {8} intend1 - intend8;
int=1;
strtdate{int}=begin_date ;
stopdate{int}=min(intnx('month',strtdate{int},4,'same')-1 ,final_date_new);
do while(stopdate{int} lt final_date_new and int lt 8);
int+1;
strtdate{int}=intnx('month',strtdate{int-1},4,'same') ;
stopdate{int}=min(intnx('month',strtdate{int},4,'same')-1 ,final_date_new);
end;
format begin_date final_date_new intstart: intend: yymmdd10.;
run;
title want;
proc print data=want;
run;
The interval start and stop variables have been renamed for ease of coding. The DO WHILE is evaluated at the top of the loop so it can be exited as soon as the criteria (exceed the end date or 8 intervals) is met.
... View more