This does not account for dates that may start not on the first of the month for date1.
data want;
set have;
by id;
if first.id;
nmonths = intck('month', date1, date2);
do i = 0 to nmonths;
month = intnx('month', date1, i, 'b');
format month yymmd7.;
num_days = intck('days', intnx('month', date1, i, 'b'), min(date2, intnx('month', date1, i, 'e')))+1;
output;
end;
keep id state month num_days;
run;
@Scooby3g wrote: state yr_month days NY 2023_01 31 NY 2023_02 4 CA 2023_07 4 The number of months would depend on how many months are between date1 and date1
... View more