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


   /* Set GOPTIONS for viewing or printing your chart              */
goptions reset=all device=xcolor target=ps300 rotate=landscape;

   /* Read in data and make preliminary calculations               */
data staff;
   input year usa gbr japan austr;
   total=sum(usa,gbr,japan,austr);
   usapct=(usa/total)*100;
   japanpct=(japan/total)*100;
   gbrpct=(gbr/total)*100;
   austrpct=(austr/total)*100;
   cards;
1990  60    15    35   35
1991  70    25    40   66
1992  128   52    65   89
1993  101   53    60   75
run;


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


proc summary data=staff max;
   var total;
   output out=totals max=maxtot n=years;
run;

   /* Specify titles and footnote                                  */
title1 f=swiss h=3.5 'PMG Inc.';
title2 f=swiss h=2 'Worldwide Personnel';
footnote1 f=swiss j=r h=1.5 'SAS/GRAPH' move=(+0,+.5) '02'x 
          move=(+0,-.5) ' Software';

   /* Begin null DATA step to produce graph using DSGI             */
data _null_;
   set staff end=eof;
   retain ymin vscale hoffset xmax xmin width;


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


if _n_=1 then do;
   set totals;
   rc=ginit();         /* initialize DSGI                          */
   rc=graph('clear');  /* open GRSEG entry in WORK.GSEG catalog    */


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


call gask('window',0,llx,lly,urx,ury,rc);

   /* Horizontal dimensions                                        */
xrange=urx-llx;             /* width of graph area                 */
xmin=.15*xrange;            /* minimum x coordinate for graph      */
xmax=.95*xrange;            /* maximum x coordinate for graph      */
width=(xmax-xmin)/years;    /* units available for each figure     */

   /* horizontal offset of each figure from origin of graph area   */
hoffset=((xmax-xmin)/2)-(((years-1)*width)/2);

   /* Vertical dimensions                                          */
yrange=ury-lly;             /* height of graph area                */
ylegend=.1*yrange;          /* space reserved for legend           */
ymin=.2*yrange;             /* minimum y coordinate for graph      */
ymax=.95*yrange;            /* maximum y coordinate for graph      */

   /* vertical scaling factor for figure                           */
   /* height to reflect data value                                 */
vscale=(ymax-ymin)/maxtot;

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


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


rc=gset('asf','texcolor','bundled');
rc=gset('asf','texfont','bundled');
rc=gset('texrep',1,1,'swiss');
rc=gset('texrep',2,6,'marker');
rc=gset('texrep',3,1,'markere');


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


rc=gset('asf','filcolor','bundled');
rc=gset('asf','filtype','bundled');
rc=gset('filrep',1,2,'solid',1);
rc=gset('filrep',2,3,'solid',1);
rc=gset('filrep',3,4,'solid',1);
rc=gset('filrep',4,5,'solid',1);
rc=gset('filrep',5,1,'hollow',1);


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


   /* scaled maximum data value used for drawing and labeling axis */
maxht=maxtot*vscale; 

   /* draw axis line                                               */
rc=gdraw('line',6,xmin-10,xmin,xmin-5,xmin-5,xmin-10,xmin,
   ymin,ymin,ymin,ymin+maxht,ymin+maxht,ymin+maxht);
  
   /* angle for text string                                        */
rc=gset('texup',-1,0);
                     
   /* horizontal and vertical alignment of text                    */
rc=gset('texalign','center','normal');      
rc=gset('texindex',1);                    /* text bundle index     */
rc=gset('texheight',4);                   /* height of text string */

   /* place axis label                                             */
rc=gdraw('text',xmin-10,(ymin+maxht/2),'Total Number of Employees');


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


rc=gset('texup',0,1);
rc=gset('texheight',4);
rc=gdraw('text',xmin-5,ymin-5,'YEAR:');

      /* Define array of location names                            */
   loc1='U.S.A. (HQ)';
   loc2='Great Britain';
   loc3='Japan';
   loc4='Australia';
array loc{*} loc1-loc4;
k=dim(loc);


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


do j=1 to k;
   if mod(k,2)=0 then num=k;
      else num=k+1;
   totrows=2;                      /* two rows of legend entries   */
   totcols=num/totrows;            /* calculate number of columns  */
                                   /* needed                       */
   xspace=(xrange-xmin)/2;         /* reference point to calculate */
                                   /* entry position               */

      /* Determine row and column location for entry               */
   if j le totcols then do;
      row=1; col=j;
   end;
   else do;
      row=2; col=j-totcols;
   end;

      /* Calculate x and y position and draw legend bar and text.  */
      /* Calculate horizontal position for legend entry            */
   xleg=xmin+(col*(xspace/totcols));
        
      /* calculate vertical position for legend entry              */
   yleg=ylegend-(row*(ylegend/totrows-1));

      /* select fill bundle index                                  */  
   rc=gset('filindex',j);
                   
      /* draw legend bar                                           */
   rc=gdraw('bar',xleg,yleg,xleg+5,yleg+3); 
   rc=gset('texalign','left','base');
   rc=gset('texheight',3);

      /* draw legend value next to bar                             */
   rc=gdraw('text',xleg+7,yleg,loc{j});     
end;

      /* Draw legend label                                         */
   rc=gset('texalign','center','base');
   rc=gset('texindex',1);
   rc=gset('texheight',4);
   rc=gdraw('text',xmin+((xspace/totcols)/2),ylegend/2,'Locations:');
end;  /* end of initialization                                     */


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


height=total*vscale;              /* scaled height of figure       */
x=(_n_-1)*width+(xmin+hoffset);   /* horizontal position of figure */


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


rc=gset('texalign','center','normal');
rc=gset('texheight',5);
rc=gdraw('text',x,ymin-5,trim(left(put(year,4.))));


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


   /* specify direction of the text string                         */
rc=gset('texpath','up');              
rc=gset('texheight',height);
rc=gset('texalign','center','base');
rc=gset('texindex',2);


   /* horizontal scaling factor to place figures next to           */
   /* one another                                                  */
xscale=5*(total/maxtot);  
rc=gdraw('text',x-xscale,ymin,'Q');   /* draw male figure          */
rc=gset('texindex',3);
rc=gdraw('text',x-xscale,ymin,'Q');   /* outline male figure       */
rc=gset('texindex',2);
rc=gdraw('text',x+xscale,ymin,'R');   /* draw female figure        */
rc=gset('texindex',3);
rc=gdraw('text',x+xscale,ymin,'R');   /* outline female figure     */
rc=gset('texpath','right');
rc=gset('texheight',4);
rc=gset('texindex',1);

   /* place data value above figure                                */
rc=gdraw('text',x,ymin+height,trim(left(put(total,comma7.))));


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


   /* pie radius scaled to maximum of 12 units                     */
pscale=12*(total/maxtot);

   /* Define array for drawing pie charts                          */
array pct{*} usapct japanpct gbrpct austrpct;

do i=1 to dim(pct);
   retain start end;
                
      /* calculate starting and ending angles for pie slice.       */
   if i=1 then start=0;          
   else start=start+(pct{i-1}*3.6);
   end=start+(pct{i}*3.6);
   rc=gset('filindex',i);
 
      /* draw pie slice                                            */
   rc=gdraw('pie',x,ymin+height/2,pscale,start,end);  
   rc=gset('filindex',5);
 
      /* outline pie slice                                         */
   rc=gdraw('pie',x,ymin+height/2,pscale,start,end);   
end;


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


if eof then do;
   rc=graph('update');          /* complete the graph and display  */
   rc=gterm();                  /* terminate DSGI                  */
end;
run;


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