Hi, I'm kind of stuck when try to generate a series of date within do loop. For iteration 0 and 1 the DATE is set with fixed formula, however starting from iteration > 1, two DATE should be generated within same month (EVENT_DAY_OF_MONTH, follow by end of month), and repeated this pattern until iteration < DURATION. data want; format START_DT END_DT DATE DATE_LAG date9.; START_DT = '19APR2018'd; EVENT_DAY_OF_MONTH = 6; END_DT = '05JAN2019'd; DURATION = intck('month',START_DT,END_DT)*2; do i=0 to DURATION by 1; if i = 0 then DATE = START_DT; if i = 1 then DATE = intnx('month',START_DT,i-1,'E'); DATE_LAG = LAG(DATE); if 1 < i < DURATION and DAY(DATE_LAG) ne EVENT_DAY_OF_MONTH then DATE = mdy(month(intnx('month',START_DT,i-1,'E')),EVENT_DAY_OF_MONTH,year(intnx('month',START_DT,i-1,'E'))); if 1 < i < DURATION and DAY(DATE_LAG) = EVENT_DAY_OF_MONTH then DATE = intnx('month',START_DT,i-1,'E'); if i = DURATION then DATE = END_DT; output; end; run; run; Sample expected result i'm looking for: 2018-04-19 2018-04-30 2018-05-06 2018-05-31 2018-06-06 2018-06-30 2018-07-06 2018-07-31 2018-08-06 2018-08-31 2018-09-06 2018-09-30 2018-10-06 2018-10-31 2018-11-06 2018-11-30 2018-12-06 2018-12-31 2019-01-05
... View more