%macro picto(inds, vvar, tvar, units);                        
                                                              
      /* PROC SORT is used to make values go in            */ 
      /* ascending order.                                  */ 
   proc sort  data=&inds;                                     
      by &vvar;           /* by number of otters           */ 
   run;                                                       
                                                              
      /* Get information for the dimensions                */         
      /* of the pictogram.                                 */         
   proc means data=&inds noprint max;                                 
      var  &vvar;            /* number of otters           */         
      output out=picsize(keep= nbars vmax)                            
             max=vmax   /* max. number of otters - width   */         
             n=nbars; /* number of manuf. plants - height  */         
   run;                                                               
                                                                      
      /* DATA step which produces the pictogram            */         
   data _null_;                                                       
         /* Arrays are used to store x-coordinates         */
         /* for symbols.                                   */         
      array pmx {18} px1-px18;                                
      retain  xmin   xmax    vmin    vmax   xlab                      
              yaxmin yaxmax  xrange  yrange pmx                       
              yaxlen ywidth  ystart  ybar   ymargn                    
              vscale nbars   ncolors pmy;                             
                                                                      
         /* Start the initialization part.                 */         
      if _n_ = 1 then do;                                             
         rc=ginit();        /* Initialize DSGI.            */         
         rc=graph('clear'); /* Open the graph to           */         
                            /* receive primitives.         */         
         set picsize;       /* summary data set            */         
                                                                      
            /* Set the colors for the symbols used         */         
            /* in the pictogram.                           */         
         rc = gset('colrep', 1, 'gray10'); /* symbol color */         
         rc = gset('colrep', 2, 'gray30'); /* symbol color */
         rc = gset('colrep', 3, 'gray50'); /* symbol color */         
         rc = gset('colrep', 4, 'gray70'); /* symbol color */         
         rc = gset('colrep', 5, 'gray90'); /* symbol color */         
         rc = gset('colrep', 6, 'grayb0'); /* symbol color */         
         rc = gset('colrep', 7, 'grayd0'); /* symbol color */         
         rc = gset('colrep', 8, 'black');  /* for text/    */         
                                           /* line color   */         
         ncolors=7;          /* seven colors for symbols   */         
                                                                      
            /* Find out the dimensions of the              */         
            /* default window.                             */         
         call gask('window', 0, x1, y1, x2, y2, rc);                  
         xrange=x2-x1; /* width of graph area in           */         
                       /* window units                     */         
         yrange=y2-y1; /* height of graph area in          */         
                       /* window units                     */         
                                                                      
            /* Locate pictogram area dimensions.           */         
         xlab   = .23*xrange; /* x-coordinate for          */
                              /* plant labels              */         
         xmin   = .25*xrange; /* min. x-dimension of pict. */
         xmax   = .95*xrange; /* max. x-dimension of pict. */
         yaxmin = .15*yrange; /* min. y-dimension of pict. */
         yaxmax = .95*yrange; /* max. y-dimension of pict. */
                                                                      
            /* YAXLEN is the range in y of the graph area. */
            /* YWIDTH is the room allowed in y for each    */
            /* symbol row.                                 */         
            /* YMARGN is the room allowed in y between     */
            /* rows.                                       */
         yaxlen=yaxmax-yaxmin;           /* y-axis length  */
         ywidth=floor(yaxlen/(nbars+1)); /* symbol height  */         
         ymargn=(yaxlen-(ywidth*nbars))/(nbars-1);                    
                                      /* room between rows */         
                                                                      
            /* Prepare minimum and maximum values.         */         
         vmin=0;    /* Include 0 in the data range.        */         
            /* Adjust the max. value to add space at       */         
            /* the end of the pict. area.                  */         
         vmax=(floor(vmax/10)+1) * 10;                                
                                                                      
            /* Compute the ratio of screen percentage to   */         
            /* data range.                                 */         
         vscale=(xmax-xmin)/(vmax-vmin);                              
                                                                      
            /* INCR is the space between symbols in        */         
            /* the x-direction.                            */
         incr=(xmax-xmin)/dim(pmx);                                   
                                                                      
            /* Calculate the x-coordinates                 */
            /* for the symbols being drawn.                */         
         do i=1 to dim(pmx);                                          
            pmx{i}=xmin+incr/2+((i-1)*incr);                  
         end;                                                         
                                                                      
            /* Calculate the value of each symbol.         */         
         symvalue=(vmax-vmin)/dim(pmx);                               
                                                                      
            /* Set time line attributes for the            */         
            /* pictogram frame.                            */
         rc=gset('lintype', 1);   /* solid line            */         
         rc=gset('linwidth', 3);  /* width of 3            */         
         rc=gset('lincolor', 8);  /* black                 */         
                                                                      
            /* Draw the frame --- x-values appear first,   */
            /* followed by y-values.                       */
         rc=gdraw('line', 5, xmin, xmax, xmax, xmin, xmin,            
                  yaxmin, yaxmin, yaxmax, yaxmax, yaxmin);            
                                                                      
            /* Set attributes for the legend text.         */         
         rc=gset('texfont', 'swissl'); /* swissl font      */         
         rc=gset('texcolor', 8);       /* black            */         
         rc=gset('texheight', 2.5);    /* height of 2.5    */         
         rc=gset('texalign', 'center', 'top');                        
            /* Center and justify the text and align based */         
            /* on the top of the text.                     */         
                                                                      
            /* Provide a legend for the pictogram.         */         
         rc=gdraw('text', .5*xrange, .13*yrange,                      
                '1 symbol = ' || left(put(symvalue, 6.2)) ||          
                %str(&units));                                        
                                                                      
            /* Begin at the top of the pictogram with the  */         
            /* shortest row.                               */         
         ystart=yaxmax;                                               
                                                                      
      end;         /* End the initialization part.         */         
                                                                      
      set &inds end=last;   /* Now read in the otter       */         
                            /* data set.                   */
         ybar=ystart-ywidth;   /* Get the y-coordinate for *
                               /* the symbols.             */        
         pmy=(ybar+ystart)/2;  /* Center text vertically   */        
                               /* in the row.              */        
                                                                     
            /* Draw the label for the manufacturing plant. */        
         rc=gset('texcolor', 8);         /* black          */        
         rc=gset('texheight', 2.5);      /* height of 2.5  */        
         rc=gset('texfont','swissl');    /* SWISSL font    */        
         rc=gset('texalign','right','half'); /* right      */        
                                             /* justify    */        
           /* Align text vertically to midpoint.           */        
         rc=gdraw('text', xlab, pmy, &tvar);                         
                                                                     
           /* Convert the data value to an x-coordinate.   */
         xval=xmin+((&vvar-vmin)*vscale);                            
                                                                     
            /* Set up the clipping viewport for the plant. */        
            /* Viewport coordinates are in a percentage    */        
            /* from 0 to 1.                                */        
         rc=gset('viewport', 1, xmin/xrange, ybar/yrange,            
                                xval/xrange, ystart/yrange);         
                                                                     
            /* Set up the scale for this viewport.         */        
         rc=gset('window', 1, xmin, ybar, xval, ystart);             
                                                                     
            /* The VIEWPORT and WINDOW functions have no   */        
            /* effect until this function is called.       */        
         rc=gset('transno', 1); /* Activate                */        
                                /* transformation.         */
         rc=gset('clip', 'on'); /* Turn viewport           */         
                                /* clipping on.            */         
                                                                      
            /* Set text attributes to draw a row           */         
            /* of symbols.                                 */         
         rc=gset('texfont', 'marker');      /* MARKER font */         
         rc=gset('texheight', 5);           /* height of 5 */         
         rc=gset('texcolor', mod(_n_, ncolors) + 1);                  
            /* Rotate through the colors listed for        */         
            /* the symbols.                                */         
         rc=gset('texalign','center','half');                         
            /* Center and justify the text.                */         
            /* Align text midpoint to point.               */         
                                                                      
            /* Draw the symbols.                           */         
         do i=1 to dim(pmx);                                          
              /* Draw text against the clipping viewport.  */         
              /* V = star symbol                           */         
            rc=gdraw('text', pmx{i}, pmy, 'v');               
         end;                                                         
         rc=gset('clip', 'off'); /* Turn clipping off.     */         
         rc=gset('transno', 0); /* Return to default       */         
                                /* transformation.         */         
         ystart=ybar-ymargn;  /* Move down y-axis to the   */
                              /* top of the next row.      */         
      if last then do;                                                
            /* These two routines are done only            */         
            /* at end-of-data-set.                         */         
         rc=graph('update');    /* Display the graph.      */         
         rc=gterm();            /* Terminate DSGI.         */
      end;                         
  run;                             
                                   
%mend picto;                       
   data pctdata;                   
      input  otters plant $char20.;
      cards;                       
   116     Westchester             
   323     Riverside               
   239     Elm Grove               
   452     Pleasant Heights        
   337     Airport                 
   399     Downtown                
   129     Gleneagle               
   533     Porterville             
   344     North Station           
   ;                               

goptions border;                                            
title f=swissl c=black h=3.5 pct                            
      'Otters Completed by Our Subcontractors, 01Jun-30Jun';
%picto(pctdata, otters, plant, 'Otters');                   
title;