options ls=65 ps=54;              
title 'Rocket Propellant Problem from Table 5-9 pg. 194';

* Read data into SAS from an external file;
filename raw '~/Montgomery/Data/tble5-9.dat';
data raw;
  infile raw;
  input block1 block2 trmt $ response;     
run;                                  

* Print the data;
proc print data=raw;         
run;

* Statistical analysis for pxp Latin Square Design;
proc glm data=raw;              
  class block1 block2 trmt;
  model response=block1 block2 trmt;
  means trmt / lsd alpha=0.05;
  output out=temp p=fit r=resid student=stdresid; 
run;

* Model adequacy checking (Residual Analysis);        
proc rank data=temp out=checkass normal=vw;
  var resid;
  ranks expected;
run;

proc print data=checkass;
  var response fit resid stdresid expected;
run;

proc plot data=checkass vpct=50 hpct=50;
  plot stdresid*trmt = '*' / vref=-2 2 vrefchar='-' box;       /*
Homogenity of 
  variance among treatment groups and outlier detection */
  plot stdresid*block1 = '*' / vref=-2 2 vrefchar='-' box;     /*
Homogenity of 
  variance among block1 and outlier detection */
  plot stdresid*block2 = '*' / vref=-2 2 vrefchar='-' box;     /*
Homogenity of
  variance among block2 and outlier detection */
  plot stdresid*fit = '*' / vref=-2 2 vrefchar='-' box;        /*
Homogenity of
  variance and interaction between blocks and treatments */
  plot expected*resid = '*' / box;                /* Normal
Probability Plot */
  plot response*trmt = '*' /box;                  /* Plot of raw data
*/    
run;

proc univariate data=checkass plot normal;
  var resid;
run;