Creating Multivariate Control Charts

/****************************************************************/
/*          S A S   S A M P L E   L I B R A R Y                 */
/*                                                              */
/*    NAME: SHWT2                                               */
/*   TITLE: Creating Multivariate Control Charts                */
/* PRODUCT: QC                                                  */
/*  SYSTEM: ALL                                                 */
/*    KEYS: Shewhart Charts, Multivariate Control Charts,       */
/*   PROCS: SHEWHART PRINCOMP MEANS                             */
/*    DATA:                                                     */
/*                                                              */
/*     REF: SAS/QC Software:  Usage and Reference, Version 6,   */
/*          First Edition, Volume 1 and Volume 2                */
/*                                                              */
/****************************************************************/

data Startup;
   input Sample Impure Temp Conc;
   label Sample = 'Sample Number'
         Impure = 'Impurities'
         Temp   = 'Temperature'
         Conc   = 'Concentration' ;
   datalines;
 1  14.92  85.77  42.26
 2  16.90  83.77  43.44
 3  17.38  84.46  42.74
 4  16.90  86.27  43.60
 5  16.92  85.23  43.18
 6  16.71  83.81  43.72
 7  17.07  86.08  43.33
 8  16.93  85.85  43.41
 9  16.71  85.73  43.28
10  16.88  86.27  42.59
11  16.73  83.46  44.00
12  17.07  85.81  42.78
13  17.60  85.92  43.11
14  16.90  84.23  43.48
;

proc means data=Startup noprint ;
   var Impure Temp Conc;
   output out=means n=n;
run;

data Startup;
   if _n_ = 1 then set means;
   set Startup;
   p        = 3;
   _subn_   = 1;
   _limitn_ = 1;
run;

proc princomp data=Startup out=Prin outstat=scores std cov;
   var Impure Temp Conc;
run;

data Prin (rename=(tsquare=_subx_));
   length _var_ $ 8 ;
   drop prin1 prin2 prin3 _type_ _freq_;
   set Prin;
   comp1   = prin1*prin1;
   comp2   = prin2*prin2;
   comp3   = prin3*prin3;
   tsquare = comp1 + comp2 + comp3;
   _var_   = 'tsquare';
   _alpha_ = 0.05;
   _lclx_  = ((n-1)*(n-1)/n)*betainv(_alpha_/2, p/2, (n-p-1)/2);
   _mean_  = ((n-1)*(n-1)/n)*betainv(0.5, p/2, (n-p-1)/2);
   _uclx_  = ((n-1)*(n-1)/n)*betainv(1-_alpha_/2, p/2, (n-p-1)/2);
   label tsquare = 'T Squared'
         comp1   = 'Comp 1'
         comp2   = 'Comp 2'
         comp3   = 'Comp 3';
run;

title 'T2 Chart For Chemical Example';
proc print data=Prin noobs;
run;

ods graphics off;
title 'T' m=(+0,+0.5) '2'
          m=(+0,-0.5) ' Chart For Chemical Example';
proc shewhart table=Prin;
   xchart tsquare*Sample /
      xsymbol  = mu
      nolegend ;
run;

title 'T' m=(+0,+0.5) '2'
          m=(+0,-0.5) ' Chart For Chemical Example';
symbol value=none;
proc shewhart table=Prin;
   xchart tsquare*Sample /
      starvertices  = (comp1 comp2 comp3)
      startype      = wedge
      starlegend    = none
      starlabel     = first
      staroutradius = 4
      npanelpos     = 14
      xsymbol       = mu
      nolegend ;
run;