Resources

Store Hours Example

/*--------------------------------------------------------------

                    SAS Sample Library

        Name: intex01.sas
 Description: Example program from SAS/ETS User's Guide,
              Date Intervals, Formats, and Functions
       Title: Store Hours Example
     Product: SAS/ETS Software
        Keys: time intervals, time functions
        PROC: interval functions
       Notes:

--------------------------------------------------------------*/

options intervalds=(StoreHours=StoreHoursDS);
data StoreHoursDS(keep=BEGIN END);
   start = '01JAN2009'D;
   stop  = '31DEC2009'D;
   do date = start to stop;
      dow = WEEKDAY(date);
      datetime=dhms(date,0,0,0);
      if dow not in (1,7) then
         do hour = 9 to 17;
            begin=intnx('hour',datetime,hour,'b');
            end=intnx('hour',datetime,hour,'e');
            output;
         end;
      else if dow = 7 then
         do hour = 9 to 12;
            begin=intnx('hour',datetime,hour,'b');
            end=intnx('hour',datetime,hour,'e');
            output;
         end;
   end;
   format BEGIN END DATETIME.;
run;


title 'Store Hours Custom Interval';
proc print data=StoreHoursDS(obs=18);
run;