Try this. I simplified your original data step a bit and added the logic to determine if a Monday is also a holiday. data hourly_p ( drop=_: ); _yr = 2002; _prv_holiday_id = 0; format date_val date9.; do date_val = mdy( 1,1,_yr ) to mdy( 12,31,_yr ); mnth = month( date_val ); dy = day( date_val ); * determine holidays; select; when (Date_val in ('01JAN2002'd,'18FEB2002'd,'27MAY2002'd,'04JUL2002'd,'22DEC2002'd, '11NOV2002'd,'02SEP2002'd,'28NOV2002'd,'25DEC2002'd ) ) Holiday_id = 1 ; * the monday following a sunday holiday is also a holiday; when ( _prv_holiday_id = 1 and weekday( date_val ) = 2 ) holiday_id = 1; otherwise Holiday_id = 0 ; end ; /* id summer/winter */ select ; when ('01JUN2002'd<=Date_val < '01OCT2002'd) Season_id = 'Summer' ; otherwise Season_id = 'Winter' ; end ; do Time_id = 1 to 24 ; /* # of hours/day */ output ; end ; * the current holiday_id becomes the previous holiday_id for the next loop; _prv_holiday_id = holiday_id; end; run;
... View more