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


   /* Read factory floor plan coordinates                  */
data flrplan(drop=i);
   length area $15;
   input area & $ @@;
   do i=1 to 4;
      input x  y  @;
      output;
   end;
cards;
Receiving  0 0 0 10 10 10 10 0
Stockroom  0 10 0 25 10 25 10 10
Auto. Assembly  10 15 10 25 20 25 20 15
Manual Assembly  20 15 20 25 30 25 30 15
Testing  30 15 30 25 45 25 45 15
Shipping  35 0 35 15 45 15 45 0
;


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


   /* Sort the FLRPLAN data set                            */
proc sort;
   by area;
run;

   /* Obtain center coordinates for each area              */
proc means data=flrplan mean noprint;
   var x y;
   by area;
   output out=centers mean=meanx meany;
run;


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


   /* Define Annotate data set                             */
data anno;
   set centers;
   length text $15;
   retain xsys ysys '2' hsys '3'
   when 'a'
   function 'label'
   style 'hwpsl019'
   position '+'
   size 3
   color 'black';
   x=meanx;
   y=meany;
   text=trim(left(area));
run;


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


   /* Create format for response variable                  */
proc format;
   value dohfmt low - 2.9 ='less than 3'
                3.0 - 5.9 ='3 to 6'
                6.0 - 10.0='6 to 10'
               10.1 - high='more than 10';
run;


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


   /* Read month-end inventory data                        */
data invdata;
   length area $15;
   input area & $ invalue thruput;
   daysoh=round(invalue*30.5/thruput,0.1);
cards;
Receiving  3550 54137
Stockroom  36200 36803
Auto. Assembly  2153 43777
Manual Assembly  4377 44500
Testing  18920 57706
Shipping  6990 71065
Factory Total  72190 71065
;


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


   /* Specify graphics options                             */
goptions reset=all device=pscolor ftext=hwpsl019
         rotate=landscape nodisplay;

   /* Specify PATTERN, LEGEND and TITLE statements         */
pattern1 value=msolid color=vpab;  /* Very pale blue       */
pattern2 value=msolid color=vpag;  /* Very pale green      */
pattern3 value=msolid color=paoy;  /* Pale orange-yellow   */
pattern4 value=msolid color=liypk; /* Light yellowish pink */

legend1 label=(height=2.5 pct justify=c 'Inventory' justify=c
        'Days On-Hand')
        value=(height=2.5 pct);

title1 height=4 pct
'Inventory Analysis - January 1996';


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


   /* Produce the floor plan                               */
proc gmap map=flrplan data=invdata gout=temp;
   id area;
   choro daysoh / discrete
                  legend=legend1
                  coutline=black
                  annotate=anno;
   format daysoh dohfmt.;
run;
quit;


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


   /* Reset titles and set system options                  */
title1;
options nodate nonumber nocenter;

   /* Define external file to be created                   */
filename tabout 'tab.out';

   /* Run PRINTTO before TABULATE to route output to file  */
proc printto new file=tabout;
run;

   /* Create table                                         */
proc tabulate data=invdata order=data;
   class area;
   var invalue thruput daysoh;
   table area='AREA:', invalue='Inventory Value'*sum=' '*f=dollar10.
              thruput='Monthly Throughput'*sum=' '*f=dollar10.
              daysoh='Inventory Days On-Hand'*sum=' '
              /rts=16;
run;

   /* Run PRINTTO after TABULATE to route output back to   */
   /* default location                                     */
proc printto;
run;


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


   /* Specify graphics options                             */
goptions hpos=50 vpos=30 ftext=hwpsl003;

   /* Use JPRINT procedure to create GRSEG entry from      */
   /* TABULATE output                                      */
proc jprint fileref=tabout gout=temp;
run;
quit;


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


   /* Specify graphics options                             */
goptions hpos=0 vpos=0 display;

   /* Combine the floor plan and table                     */
proc greplay nofs igout=temp gout=temp;
tc temp;
tdef invntory 1/
              2/llx=30 lly=10
                ulx=30 uly=50
                urx=70 ury=50
                lrx=70 lry=10
              ;
template invntory;
tplay 1:gmap 2:jprint;
run;
quit;


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