Boxchart with Summary Statistics

 /****************************************************************/
 /*          S A S   S A M P L E   L I B R A R Y                 */
 /*                                                              */
 /*    NAME: SHWBLK3                                             */
 /*   TITLE: Boxchart with Summary Statistics                    */
 /* PRODUCT: QC                                                  */
 /*  SYSTEM: ALL                                                 */
 /*    KEYS: Shewhart Charts, Box Charts,                        */
 /*   PROCS: SHEWHART MEANS                                      */
 /*    DATA:                                                     */
 /*                                                              */
 /*     REF: SAS/QC Software:  Examples                          */
 /*    MISC: This sample list the subgroup sample size, mean,    */
 /*          and standard deviation in the boxchart table.       */
 /*          This program can be modified to produce a table     */
 /*          containing a different set of summary statistics.   */
 /*                                                              */
 /****************************************************************/
options ps=60 ls=80 nodate;

title 'Boxchart with Summary Statistics';

data one;
   do subgrp = 1 to 15;
      input n mean std;
      do i = 1 to n;
         x = mean + std*rannor(234111);
         output;
         end;
   end;
   drop i n mean std;
cards;
60 7.3 .55
73 7.1 .65
59 6.7 .45
83 7.0 .50
70 7.6 .70
92 7.3 .55
73 6.7 .55
89 7.1 .45
55 6.9 .50
68 6.8 .68
53 7.1 .50
96 7.4 .66
64 6.8 .35
75 7.0 .50
80 7.0 .40
;

 * Compute subgroup size, mean, and standard deviation ;

proc means data=one noprint;
   by subgrp;
   var x;
   output out=stats n=n mean=mean std=std;
run;

 * Create block variables used to produce table ;

data blocks;
   keep block1 block2 block3 subgrp;
   set stats;
      blck1 = n;
      blck2 = mean;
      blck3 = std;
   blck1 = put(blck1,10.2);
   blck2 = put(blck2,10.2);
   blck3 = put(blck3,10.2);
   block1 = left(blck1);
   block2 = left(blck2);
   block3 = left(blck3);
   if _n_ = 1 then do;
      block1 = 'N      '||block1;
      block2 = 'Mean   '||block2;
      block3 = 'Std    '||block3;
      end;
   run;

data two;
   merge one blocks;
   by subgrp;
run;

symbol1 v=dot h=.75 c=white;
proc shewhart data=two;
   boxchart x*subgrp (block3 block2 block1 ) /
                   blocklabtype  = scaled
                   blockpos      = 4
                   stddevs
                   boxwidthscale = 1
                   blockrep
                   boxstyle      = schematic
                   nolegend
                   novangle
                   hoffset       = 4
                   cframe        = gray
                   cboxfill      = blue
                   cboxes        = white
                   nolimits;
   run;

goptions reset=all;