CALENDAR Procedure

Example 3: Multiple Schedule Calendars with Atypical Work Shifts (Separated Output)

Features:
PROC CALENDAR statement options:
CALEDATA=
DATETIME
WORKDATA=
CALID statement:
_CAL_ variable
OUTPUT=SEPARATE option
Other statements::
DUR statement
OUTSTART statement
OUTFIN statement

Details

This example does the following:
  • produces separate output pages for each calendar in a single PROC step
  • schedules activities around holidays
  • displays an 8-hour day, 5 1/2-day week
  • uses separate work patterns and holidays for each calendar

Producing Different Output for Multiple Calendars

This example and Multiple Schedule Calendars with Atypical Work Shifts (Combined and Mixed Output) use the same input data for multiple calendars to produce different output. The only differences in these programs are how the activities data set is sorted and how the OUTPUT= option is set.
Sort and OUTPUT= Settings
Print Options
Sorting Variables
OUTPUT= Settings
Examples
Separate pages for each calendar
Calendar ID and starting date
SEPARATE
3, 8
All activities on the same page and identify each calendar
Starting date
COMBINE
4, 2
All activities on the same page and NOT identify each calendar
Starting date
MIX
4

Program

libname well 'SAS-library';
data well.act;
   input task & $16. dur : 5. date : datetime16.  _cal_ $ cost;
   datalines;
Drill Well          3.50  01JUL02:12:00:00  CAL1   1000
Lay Power Line      3.00  04JUL02:12:00:00  CAL1   2000
Assemble Tank       4.00  05JUL02:08:00:00  CAL1   1000
Build Pump House    3.00  08JUL02:12:00:00  CAL1   2000
Pour Foundation     4.00  11JUL02:08:00:00  CAL1   1500
Install Pump        4.00  15JUL02:14:00:00  CAL1    500
Install Pipe        2.00  19JUL02:08:00:00  CAL1   1000
Erect Tower         6.00  20JUL02:08:00:00  CAL1   2500
Deliver Material    2.00  01JUL02:12:00:00  CAL2    500
Excavate            4.75  03JUL02:08:00:00  CAL2   3500
;
data well.hol;
   input date date. holiday $ 11-25 _cal_ $;
   datalines;
09JUL02   Vacation            CAL2
04JUL02   Independence        CAL1
;
data well.cal;
   input _sun_ $ _sat_ $ _mon_ $ _tue_ $ _wed_ $ _thu_ $
         _fri_ $ _cal_ $;
   datalines;
Holiday Holiday  Workday Workday Workday Workday Workday CAL1
Holiday Halfday  Workday Workday Workday Workday Workday CAL2
;
data well.wor;
   input halfday time5.;
   datalines;
08:00
12:00
;
proc sort data=well.act;
   by _cal_ date;
run;
options formchar="|----|+|---+=|-/\<>*";
proc calendar data=well.act
              holidata=well.hol
              caledata=well.cal
              workdata=well.wor
              datetime;
   calid _cal_ / output=separate;
   start date;
   dur dur;
   holistart date;
   holivar holiday;
   outstart Monday;
   outfin Saturday;
   title1 'Well Drilling Work Schedule: Separate Calendars';
   format cost dollar9.2;
run;

Program Description

Specify a library so that you can permanently store the activities data set.
libname well 'SAS-library';
Create the activities data set and identify separate calendars. WELL.ACT is a permanent SAS data set that contains activities for a well construction project. The _CAL_ variable identifies the calendar that an activity belongs to.
data well.act;
   input task & $16. dur : 5. date : datetime16.  _cal_ $ cost;
   datalines;
Drill Well          3.50  01JUL02:12:00:00  CAL1   1000
Lay Power Line      3.00  04JUL02:12:00:00  CAL1   2000
Assemble Tank       4.00  05JUL02:08:00:00  CAL1   1000
Build Pump House    3.00  08JUL02:12:00:00  CAL1   2000
Pour Foundation     4.00  11JUL02:08:00:00  CAL1   1500
Install Pump        4.00  15JUL02:14:00:00  CAL1    500
Install Pipe        2.00  19JUL02:08:00:00  CAL1   1000
Erect Tower         6.00  20JUL02:08:00:00  CAL1   2500
Deliver Material    2.00  01JUL02:12:00:00  CAL2    500
Excavate            4.75  03JUL02:08:00:00  CAL2   3500
;
Create the holidays data set. The _CAL_ variable identifies the calendar that a holiday belongs to.
data well.hol;
   input date date. holiday $ 11-25 _cal_ $;
   datalines;
09JUL02   Vacation            CAL2
04JUL02   Independence        CAL1
;
Create the calendar data set. Each observation defines the work shifts for an entire week. The _CAL_ variable identifies to which calendar the work shifts apply. CAL1 uses the default 8-hour work shifts for Monday through Friday. CAL2 uses a half day on Saturday and the default 8-hour work shift for Monday through Friday.
data well.cal;
   input _sun_ $ _sat_ $ _mon_ $ _tue_ $ _wed_ $ _thu_ $
         _fri_ $ _cal_ $;
   datalines;
Holiday Holiday  Workday Workday Workday Workday Workday CAL1
Holiday Halfday  Workday Workday Workday Workday Workday CAL2
;
Create the workdays data set. This data set defines the daily work shifts that are named in the calendar data set. Each variable (not observation) contains one daily schedule of alternating work and nonwork periods. The HALFDAY work shift lasts 4 hours.
data well.wor;
   input halfday time5.;
   datalines;
08:00
12:00
;
Sort the activities data set by the variables that contain the calendar identification and the starting date, respectively. You are not required to sort the holidays data set.
proc sort data=well.act;
   by _cal_ date;
run;
Set the FORMCHAR option.Setting FORMCHAR to this exact string renders better HTML output when it is viewed outside of the SAS environment where SAS Monospace fonts are not available.
options formchar="|----|+|---+=|-/\<>*";
Create the schedule calendar. DATA= identifies the activities data set; HOLIDATA= identifies the holidays data set; CALEDATA= identifies the calendar data set; WORKDATA= identifies the workdays data set. DATETIME specifies that the variable specified with the START statement contains values in SAS datetime format.
proc calendar data=well.act
              holidata=well.hol
              caledata=well.cal
              workdata=well.wor
              datetime;
Print each calendar on a separate page. The CALID statement specifies that the _CAL_ variable identifies calendars. OUTPUT=SEPARATE prints information for each calendar on separate pages.
   calid _cal_ / output=separate;
Specify an activity start date variable and an activity duration variable. The START statement specifies the variable in the activities data set that contains the activity starting date; DUR specifies the variable that contains the activity duration. START and DUR are required for a schedule calendar.
   start date;
   dur dur;
Retrieve holiday information. HOLISTART and HOLIVAR specify the variables in the holidays data set that contain the start date and name of each holiday, respectively. HOLISTART is required when you use a holidays data set.
   holistart date;
   holivar holiday;
Customize the calendar appearance. OUTSTART and OUTFIN specify that the calendar display a 6-day week, Monday through Saturday.
   outstart Monday;
   outfin Saturday;
Specify the title and format the Cost variable.
   title1 'Well Drilling Work Schedule: Separate Calendars';
   format cost dollar9.2;
run;

Output: HTML

Well Drilling Work Schedule, CAL1
Well Drilling Work Schedule, CAL2