/**********************************************************************/


   /* Read data */
data daily;
infile cards missover;
retain machine ec date;
if _n_=1 then input machine $ ec date date7.;
else do;
   input hour hrlyprod (code1-code3) ($);
   output;
end;

   /* Create macro variable containing SAS date value for     */
   /* use in title                                            */
call symput('day',put(date,date7.));
cards;
AB92161 400 19MAY96
0 310 03
1 370 99
2 375 99
3 189 02 03
4 290 03
5 373 99
6 370 99
7 212 01 02
8 399 99
9 325 99
10 350 99
11 380 99
12 345 99
13 340 99
14 380 99
15 300 01
16 385 99
17 390 99
18 250 02
19 395 99
20 399 99
21 400 99
22 355 99
23 310 01
;
run;

   /* Select the Arial Bold Truetype font                     */
%let font=hwdmx016;

   /* Set graphics options                                    */
goptions reset=all device=winprtg rotate=landscape;

   /* Begin null DATA step to produce graph with DSGI         */
data _null_;
set daily end=eof;

   /* Initialize DSGI and make preliminary assignments        */
   /* and calculations                                        */
if _n_=1 then do;

      /* Activate DSGI                                        */
   rc=ginit();

      /* Open GRSEG entry named DAILY in WORK.GSEG catalog    */
   rc=graph('clear','daily');

   /* Query active window dimensions                          */
call gask('window',0,llx,lly,urx,ury,rc);

   /* Calculate maximum radius for each clock relative        */
   /* to window width                                         */
maxrad=urx/5;

   /* Determine width of active window                        */
xrange=urx-llx;

   /* Determine horizontal (X) center of active window        */
middlex=xrange/2;

   /* Determine X position for center of A.M. and P.M. clocks */
amloc=middlex-(middlex/2);
pmloc=middlex+(middlex/2);

   /* Associate colors with color index values                */
rc=gset('colrep',1,'gray88');
rc=gset('colrep',2,'grayaa');
rc=gset('colrep',3,'grayee');
rc=gset('colrep',4,'black');

   /* Draw titles, footnote and chart labels                  */
   /* Set text font                                           */
rc=gset('texfont',"&font");

   /* Set text color                                          */
rc=gset('texcolor',4);

   /* Align text relative to (X,Y) location                   */
rc=gset('texalign','center','base');

   /* Set text height to 3 window units                       */
rc=gset('texheight',3);

   /* Draw first title line                                   */
rc=gdraw('text',middlex,90,"HOURLY PRODUCTION REPORT");

   /* Draw second title line                                  */
rc=gdraw('text',middlex,86,"machine "||left(trim(machine))
    ||"  EC: "||trim(left(ec)));

   /* Set text height                                         */
rc=gset('texheight',2.5);

   /* Draw third title line                                   */
rc=gdraw('text',middlex,82,"DATE: 
         "||trim(left(put(date,date7.))));

   /* Draw labels for A.M. and P.M. clocks                    */
rc=gdraw('text',amloc, 80,"A.M.");
rc=gdraw('text',pmloc, 80,"P.M.");

   /* Draw footnote                                           */
rc=gdraw('text',middlex,10,"REASON CODES:  01=SHIFT CHANGE  "||
   "02=ROUTINE MAINTENANCE  03=EQUIPMENT FAILURE/REPAIR");

   /* Set line color                                          */
rc=gset('lincolor',4);

   /* Draw border around graph output area                    */
rc=gdraw('line',5,0,0,urx,urx,0,0,100,100,0,0);

   /* Draw outline for A.M. and P.M. clocks                   */
rc=gdraw('pie',amloc,50,maxrad,0,360);
rc=gdraw('pie',pmloc,50,maxrad,0,360);

   /* Set starting and ending angles for first hour on clock  */
stangle=60;
eangle=90;
end;

   /* Determine whether hour is on A.M. or P.M. clock         */
if hour lt 12 then horigin=amloc;
else if hour ge 12 then horigin=pmloc;

retain middlex amloc pmloc stangle eangle maxrad;

   /* Decrement starting and ending angles as the data are    */
   /* read                                                    */
if _n_ gt 1 then do;
   stangle=stangle-30;
   eangle=eangle-30;
end;

   /* Starting and ending angles change beginning with        */
   /* 3 o'clock                                               */
if hour=3 then do;
   stangle=330;
   eangle=360;
end;

   /* Assign fill index based on hourly production value      */
if 0 <= hrlyprod <= 199 then color=1;  /* GRAY88 for values   */
                                       /* lt 200              */
else if 200 <= hrlyprod <= 299 then color=2; /* GRAYAA for    */
                                             /* 200-299       */
else if 300 <= hrlyprod then color=3;  /* GRAYEE for 300 or   */
                                       /* higher              */

   /* Calculate radius for filling the slice relative to EC */
radius=maxrad*(hrlyprod/ec);

   /* Fill each pie slice to reflect production output for    */
   /* the hour                                                */
rc=gset('filtype','solid');
rc=gset('filcolor',color);
rc=gdraw('pie',horigin,50,radius,stangle,eangle);

   /* Outline each slice to define maximum size               */
rc=gset('filtype','hollow');
rc=gset('filcolor',4);
rc=gdraw('pie',horigin,50,maxrad,stangle,eangle);

   /* Make calculations for labeling the clock                */
   /* Convert angle at center of slice to radians             */
txtangle=(eangle-15)*arcos(-1)/180;

   /* Calculate X & Y locations for placing text inside the   */
   /* fill area                                               */
xinside=horigin+((radius-3)*cos(txtangle));
yinside=50+((radius-3)*sin(txtangle));

   /* Calculate X & Y locations for placing text outside the  */
   /* fill area                                               */
xoutside=horigin+((radius+3)*cos(txtangle));
youtside=50+((radius+3)*sin(txtangle));

   /* Convert starting angle to radians for labeling the      */
   /* hours around the clock                                  */
hrangle=stangle*arcos(-1)/180;

   /* Calculate X & Y locations for placing hour value on     */
   /* the clock                                               */
xhour=horigin+((maxrad+3)*cos(hrangle));
yhour=50+((maxrad+3)*sin(hrangle));

   /* Set text alignment and height values                    */
rc=gset('texalign','center','half');
rc=gset('texheight',2.5);

   /* Place hourly production value inside filled slice       */
rc=gdraw('text',xinside,yinside,trim(left(put(hrlyprod,$5.))));

   /* Label each hour around the clock face                   */
rc=gdraw('text',xhour,yhour,trim(left(hour+1))||":00");

   /* Combine the reason codes into one text string           */
array codes{*} code1-code3;
do i=1 to 3;
   length codelist $11;
      if codes{i} not in('99' '  ') then do;
      codelist=trim(left(codelist))||'*'||trim(left(codes{i}));
      end;
end;

   /* Set text height                                         */
rc=gset('texheight',2);

   /* Label reason codes outside filled slice                 */
rc=gdraw('text',xoutside,youtside,codelist);

   /* Sum the hourly production values to report a daily      */
   /* total                                                   */
totprod+hrlyprod;

if eof then do;
 
   /* Set text alignment and height values                    */
rc=gset('texalign','center','base');
rc=gset('texheight',2.5);

   /* Report daily total on chart                             */
rc=gdraw('text',middlex,78,"daily total: "||trim(left(totprod)));

   /* Display the graph                                       */
rc=graph('update');

   /* Terminate DSGI                                          */
rc=gterm();
end;
run;


/**********************************************************************/