/* Milliken and Johnson Paint-Paving Example Sec 8.3 */
options linesize=80 pagesize=50;
data expt;
   infile 'ptpav.dat';
   input paint $ paving $ rep weeks;

proc anova; /* Table 8.1 means, 8.2 analysis of variance */
   class paint paving;
   model weeks = paint paving paint*paving;
   means paint paving paint*paving;

proc glm;  /* contrast statements only work with glm--not anova */
   class paint paving;
   model weeks = paint paving paint*paving / ss1;
   /* Table 8.3 main-effect hypotheses */
   contrast 'Yellow I vs. Yellow II' paint 0 0 1 -1;
   contrast 'White I vs. White II' paint 1 -1 0 0;
   contrast 'Yellow vs. White' paint -1 -1 1 1;
   contrast 'Asphalt I vs. Asphalt II' paving 1 -1 0;
   contrast 'Asphalt vs. Concrete' paving 1 1 -2;
   /* Table 8.4 interaction hypotheses */
   contrast 'Yellow*Asphalt' paint*paving 0 0 0 0 0 0 1 -1 0 -1 1 0;
   contrast 'White*Asphalt' paint*paving 1 -1 0 -1 1 0;
   contrast 'Color*Asphalt' paint*paving -1 1 0 -1 1 0 1 -1 0 1 -1 0;
   contrast 'Yellow*Type' paint*paving 0 0 0 0 0 0 1 1 -2 -1 -1 2;
   contrast 'White*Type' paint*paving 1 1 -2 -1 -1 2;
   contrast 'Color*Type' paint*paving -1 -1 2 -1 -1 2 1 1 -2 1 1 -2;

/* below do contrasts using variables in glm instead */
data b; set expt;
   yellow = 0;
   if paint = 'y1' then yellow = 1;
   if paint = 'y2' then yellow = 2;
   white = 0;
   if paint = 'w1' then white = 1;
   if paint = 'w2' then white = 2;
   color = 'w';
   if paint = 'y1' or paint = 'y2' then color = 'y';
   asphalt = 0;
   if paving = 'a1' then asphalt = 1;
   if paving = 'a2' then asphalt = 2;
   type = 'a';
   if paving = 'c' then type = 'c';
proc glm; /* note that color is before yellow,white and type before asphalt */
   class yellow white color asphalt type;
   model weeks = color yellow white type asphalt
      color*type yellow*type white*type
      color*asphalt yellow*asphalt white*asphalt / ss1;
/* plot the means as interaction plot */
data c; set b;
   painter = yellow;
   if painter = 0 then painter = 2 + white;
proc sort; by paint paving;
proc means noprint; by paint paving;
   var weeks painter asphalt;
   output out=means mean=mweeks mpaint masphalt;
proc plot;
   plot mweeks*mpaint=masphalt;

   