* Richard A. DeVenezia 6/2/2001; * HTML calendar example; * fake data; data usage2000; format date mmddyy10.; do date = '01jan00'd to '31dec00'd; do hour = 0 to 23; remaining = 1; do category = 'Novice', 'Intermediate', 'Expert', 'Guest'; utilization = min (.5*ranuni(0), remaining); * if weekday(date) = 7 then utilization = .10 * utilization; * saturday; output; remaining ++ -utilization; if remaining < 0 then remaining = 0; end; category = 'Other'; utilization = remaining; output; end; end; drop remaining; run; * compute a daily average utilization (dmu) and normalize it (dmuz) per month * so that in each month there is at least on one day and category * which has dmuz=100. This fact can be used when ordering the vbar * response axis and will result in the vbars for all days in a month to be * monthwise normal and ensure 'fuller' charts; *; proc sql; create view summary2000 as select * , 100 * dmu / max(dmu) as dmuz label='Month Normalized Daily Mean Utilization %' from ( select date , category , sum(utilization) / 24 as dmu label='Daily Mean Utilization' from usage2000 group by date, category ) group by month(date) order by date ; quit; %macro MonthOfCharts (year=2000, month=1, leftDay=1, path=, body=); * leftDay - the SAS day of the week to place at the left edge * of the calendar table (1=Sunday,...,7=Saturday); * path - where image files and html should be created * body - name of html file to create * ods trace on / label; ods html path=&path body=&body; goptions device=gif; goptions hby=0 hsize=.5in vsize=.75in hpos=10; goptions goutmode=append ; goptions goutmode=replace ; title; footnote; axis1 label=NONE value=NONE major=NONE minor=NONE ; axis2 label=NONE value=NONE major=NONE minor=NONE order=0 to 100; * ods output "VBAR chart of category"=gchartOdsInfo; proc gchart data=summary2000; where year(date) = &year and month(date) = &month; * Name the generated chart objects DAYnnnnn (Day In Month) * gchart was told to process by date, so it will automatically * increment each chart object name and * we will end up with DAY00001 to DAY00031; * Since we specified the ods path and body these operating * system files will be created: * vbar.html (we will rewrite this later) * day000001.gif * ... * day000031.gif *; by date; vbar category / sumvar=dmuz maxis=axis1 raxis=axis2 noframe noaxis name="DAY00001" ; label dmuz = '00'x; run; quit; goptions hby=; goptions hsize= vsize= hpos=; goptions device=win; ods html close; * ods output close; * ods trace off; * produce a calendar table; data _null_ ; filename = &path || '\' || &body; file dummy filevar=filename; date = mdy (&month, 1, &year); format date mmddyy10.; title = "Utilitzation for " || put(date,monname.) || " &year"; put "<" "HTML><" "TITLE>" title "<" "BODY>"; put "<" "H2 ALIGN=CENTER>" @; put date monname. " &year" @; put ""; * must match weekday() function results; array _weekday [7] $3 _temporary_ ('Sun' 'Mon' 'Tue' 'Wed' 'Thu' 'Fri' 'Sat'); put "<" "TABLE ALIGN=CENTER CELLSPACING=12 BORDER=1>"; put "<" "TR>"; day = &leftDay; do i = 1 to 7; put "<" "TD ALIGN=CENTER>" _weekday [ day ] +(-1) ""; day ++ 1; if day > 7 then day = 1; end; put ""; array calendar [ 42 ] _temporary_; d = weekday (date); dimIndex = d + (1 - &leftDay); if dimIndex < 1 then dimIndex ++ 7; dimValue = 1; do while (month(date) = &month); calendar [ dimIndex ] = dimValue; dimIndex ++ 1; dimValue ++ 1; date ++ 1; end; i = 1; date = mdy (&month, 1, &year); do while (month (date) = &month); put ""; do j = 1 to 7; put "" @; if calendar [i] ne . then do; gif = quote ('day000' || put(calendar[i],z2.) || '.gif'); put "" calendar[i] "" @; date ++ 1; end; else do; put ' ' @; end; put ""; i ++ 1; end; put ""; end; put ""; put ""; run; %mend MonthOfCharts; options mprint; %MonthOfCharts(year=2000, month=3, leftDay=1, path='C:\temp\report', body='vbar.html');