options ps=60 ls=80 pageno=1 formdlim='_';

data chemical;
input yield alcohol $ base $;
cards;
91.3 a1 b1
91.4 a1 b1
89.9 a1 b1
94.4 a1 b1
90.7 a1 b2
94.7 a1 b2
89.5 a1 b2
85.2 a1 b2
89.9 a2 b3
92.3 a2 b3
92.6 a2 b3
94.4 a2 b3
88.1 a2 b4
93.1 a2 b4
90.8 a2 b4
98.1 a2 b4
79.5 a3 b5
70.1 a3 b5
79.7 a3 b5
76.1 a3 b5
87.6 a3 b6
89.8 a3 b6
88.2 a3 b6
87.7 a3 b6
;

/* The convention to specify a nested factor in SAS is to use B(A); that is,
B is nested within A. */

proc glm;
class alcohol base;
model yield = alcohol base(alcohol);
means alcohol base(alcohol);
lsmeans base(alcohol)/pdiff cl; /*gives all possible pairwise intervals */
run;

/* Since B(A) is significant, let's compare the means of B within each level of A */

proc glm;
class alcohol base;
model yield = alcohol base(alcohol);
contrast 'b2-b1 within a1' base(alcohol) -1 1 0 0 0 0;
contrast 'b4-b3 within a2' base(alcohol) 0 0 -1 1 0 0;
contrast 'b6-b5 within a3' base(alcohol) 0 0 0 0 -1 1;
run;

/* Had base (B) not been significant, we could have pushed forward by comparing the levels
of alcohol (A). Note that since B really is significant, the analysis below is almost
meaningless. */

proc glm;
class alcohol base;
model yield = alcohol base(alcohol);
lsmeans alcohol/pdiff cl;
run;