It is probably easier to use a FORMAT to calculate the SEASON.
data have;
id+1;
input STD :yymmdd. ENDT :yymmdd.;
format std endt yymmdd10.;
datalines4;
2016-06-02 2016-09-24
2016-06-15 2016-09-26
2016-06-19 2016-09-30
2016-01-15 2016-02-28
;;;;
proc format ;
value $season
'0101'-'0315','1216'-'1231' = 'WINTER'
'0316'-'0615' = 'SPRING'
'0616'-'0815' = 'SUMMER'
'0816'-'1215' = 'FALL'
;
run;
Then you can just loop over all of the days in the period and output a new record when the season changes.
data want;
set have ;
season_start = put(put(std,mmddyyn4.),$season.);
season_end = put(put(endt,mmddyyn4.),$season.);
subperiod_start = std ;
season=season_start ;
do date=std to endt while (season ne season_end);
if put(put(date,mmddyyn4.),$season.) ne season then do;
subperiod_end = date - 1;
output;
subperiod_start=date ;
subperiod_end=.;
season=put(put(date,mmddyyn4.),$season.);
end;
end;
if missing(subperiod_end) then do;
subperiod_end=endt ;
output;
end;
format date subperiod_start subperiod_end yymmdd10.;
drop date;
run;
Results
... View more