CALENDAR Procedure

Example 7: Summary Calendar with MEAN Values by Observation

Features:
CALID statement:
_CAL_ variable
OUTPUT=SEPARATE option
Other statements:
FORMAT statement
LABEL statement
MEAN statement
SUM statement
Other features:

PROC FORMAT: PICTURE statement

Details

This example does the following:
  • produces a summary calendar
  • displays holidays
  • produces sum and mean values by business day (observation) for three variables
  • prints a legend and uses variable labels
  • uses picture formats to display values
To produce MEAN values based on the number of days in the calendar month, use MEANTYPE=NDAYS. By default, MEANTYPE=NOBS, which calculates the MEAN values according to the number of days for which data exists.

Program

data meals;
   input date : date7. Brkfst Lunch Dinner;
   datalines;
01Dec08       123 234 238
02Dec08       188 188 198
03Dec08       123 183 176
04Dec08       200 267 243
05Dec08       176 165 177
08Dec08       178 198 187
09Dec08       165 176 187
10Dec08       187 176 231
11Dec08       176 187 222
12Dec08       187 187 123
15Dec08       176 165 177
16Dec08       156   . 167
17Dec08       198 143 167
18Dec08       178 198 187
19Dec08       165 176 187
22Dec08       187 187 123
;
data closed;
   input date date. holiday $ 11-25;
   datalines;
26DEC08   Repairs
29DEC08   Repairs
30DEC08   Repairs
31DEC08   Repairs
23DEC08   Vacation
24DEC08   Christmas Eve
25DEC08   Christmas
;
proc sort data=meals;
   by date;
run;
proc format;
   picture bfmt other = '000 Brkfst';
   picture lfmt other = '000 Lunch ';
   picture dfmt other = '000 Dinner';
run;
options formchar="|----|+|---+=|-/\<>*";
proc calendar data=meals holidata=closed;
   start date;
   holistart date;
   holiname holiday;
   sum brkfst lunch dinner / format=4.0;
   mean brkfst lunch dinner / format=6.2;
   label brkfst = 'Breakfasts Served'
         lunch  = '   Lunches Served'
         dinner = '   Dinners Served';
   format brkfst bfmt.
          lunch lfmt.
          dinner dfmt.;
   title 'Meals Served in Company Cafeteria';
   title2 'Mean Number by Business Day';
run;
title;

Program Description

Create the activities data set.MEALS records how many meals were served for breakfast, lunch, and dinner on the days that the cafeteria was open for business.
data meals;
   input date : date7. Brkfst Lunch Dinner;
   datalines;
01Dec08       123 234 238
02Dec08       188 188 198
03Dec08       123 183 176
04Dec08       200 267 243
05Dec08       176 165 177
08Dec08       178 198 187
09Dec08       165 176 187
10Dec08       187 176 231
11Dec08       176 187 222
12Dec08       187 187 123
15Dec08       176 165 177
16Dec08       156   . 167
17Dec08       198 143 167
18Dec08       178 198 187
19Dec08       165 176 187
22Dec08       187 187 123
;
Create the holidays data set.
data closed;
   input date date. holiday $ 11-25;
   datalines;
26DEC08   Repairs
29DEC08   Repairs
30DEC08   Repairs
31DEC08   Repairs
23DEC08   Vacation
24DEC08   Christmas Eve
25DEC08   Christmas
;
Sort the activities data set by the activity starting date. You are not required to sort the holidays data set.
proc sort data=meals;
   by date;
run;
Create picture formats for the variables that indicate how many meals were served.
proc format;
   picture bfmt other = '000 Brkfst';
   picture lfmt other = '000 Lunch ';
   picture dfmt other = '000 Dinner';
run;
Set the FORMCHAR and LINESIZE options.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 summary calendar. DATA= identifies the activities data set; HOLIDATA= identifies the holidays data set. The START statement specifies the variable in the activities data set that contains the activity starting date; START is required.
proc calendar data=meals holidata=closed;
   start date;
Retrieve holiday information. The HOLISTART and HOLIVAR statements specify the variables in the holidays data set that contain the start date and the name of each holiday, respectively. HOLISTART is required when you use a holidays data set.
   holistart date;
   holiname holiday;
Calculate, label, and format the sum and mean values. The SUM and MEAN statements calculate sum and mean values for three variables and print them with the specified format. The LABEL statement prints a legend and uses labels instead of variable names. The FORMAT statement associates picture formats with three variables.
   sum brkfst lunch dinner / format=4.0;
   mean brkfst lunch dinner / format=6.2;
   label brkfst = 'Breakfasts Served'
         lunch  = '   Lunches Served'
         dinner = '   Dinners Served';
   format brkfst bfmt.
          lunch lfmt.
          dinner dfmt.;
Specify the titles.
   title 'Meals Served in Company Cafeteria';
   title2 'Mean Number by Business Day';
run;
title;

Output: HTML

Meals Served in Company Cafeteria - Mean Number by Business Day