* This is file GUM.SAS ;
title 'Two way repeat measures ANOVA -- Gum data';
* read in data set -- NO MISSING DATA (Table 9-15) ;
DATA;
infile gum;
input pH G T20 T30 S1 S2 S3 S4 S5 S6 S7 T Subj;
GT20=G*T20;
GT30=G*T30;
GS1=S1*G;
GS2=S2*G;
GS3=S3*G;
GS4=S4*G;
GS5=S5*G;
GS6=S6*G;
GS7=S7*G;
T20S1=S1*T20;
T20S2=S2*T20;
T20S3=S3*T20;
T20S4=S4*T20;
T20S5=S5*T20;
T20S6=S6*T20;
T20S7=S7*T20;
T30S1=S1*T30;
T30S2=S2*T30;
T30S3=S3*T30;
T30S4=S4*T30;
T30S5=S5*T30;
T30S6=S6*T30;
T30S7=S7*T30;
LABEL pH='plaque pH'
G='dummy variable =-1 if bicarb gum'
T20='dummy variable = 1 if 20 min'
T30='dummy variable = 1 if 30 min'
GT20='interaction of gum and T20'
GT30='interaction of gum and T30'
S1='dummy variable =1 if subject 1'
S2='dummy variable =1 if subject 2'
S3='dummy variable =1 if subject 3'
S4='dummy variable =1 if subject 4'
S5='dummy variable =1 if subject 5'
S6='dummy variable =1 if subject 6'
S7='dummy variable =1 if subject 7'
GS1='interaction of gum and subject1'
T20S1='interaction of T20 and Subject1'
T30S7='interaction of T30 and Subject7'
T='level of time factor'
Subj='Subject number';
* Do analysis of variance using regression with dummy variables ;
proc REG;
model pH=S1-S7 GS1-GS7 G T20 T30 GT20 GT30 T20S1-T20S7 T30S1-T30S7 /ss1;
* Do analysis of variance using proc GLM with RANDOM subcommand to ;
* specify the Subjects factor as random: Note that if there is an ;
* interaction involving a random command, the interaction is also a ;
* random effect and must be included in the random list -- SAS does ;
* not take care of this automatically. ;
proc GLM;
class G T Subj;
model pH=G|T Subj*G Subj*T Subj/solution;
random Subj Subj*G Subj*T;
lsmeans G T G*T/stderr pdiff;
* Use SORT and TRANSPOSE to convert data set ;
* into form where each row contains the repeated ;
* observations from each subject, which is the ;
* easiest way to get SAS to do traditional ANOVA ;
DATA;
set;
keep pH Subj;
proc SORT;
by Subj;
proc TRANSPOSE;
Var pH;
by Subj;
DATA;
set;
keep COL1-COL6;
rename COL1=NoGumT0 COL2=NoGumT20 COL3=NoGumT30 COL4=GumT0
COL5=GumT20
COL6=GumT30;
* Do traditional analysis of variance on transposed ;
* data set. Notice that the model statement contains ;
* no "class" variables, because there is only one ;
* factor that, because it has repeated measures, is ;
* represented only by the 6 "dependent" variables, ;
* NoGumTn to GumTn that identify the treatment groups ;
proc ANOVA;
model NoGumT0 NoGumT20 NoGumT30 GumT0 GumT20 GumT30=;
repeated GUM 2, TIME 3/nom;
* REPEAT ANALYSIS, for MISSING DATA (Table 9-17) ;
* read in data set -- MISSING DATA ;
DATA;
infile gummis;
input pH G T20 T30 S1 S2 S3 S4 S5 S6 S7 T Subj;
LABEL pH='plaque pH'
G='dummy variable =-1 if bicarb gum'
T='level of time factor'
Subj='Subject number';
* Do analysis of variance using proc GLM with RANDOM subcommand to ;
* specify the Subjects factor as random: Note that if there is an ;
* interaction involving a random command, the interaction is also a ;
* random effect and must be included in the random list -- SAS does ;
* not take care of this automatically. ;
proc GLM;
class G T Subj;
model pH=G|T Subj*G Subj*T Subj/solution;
random Subj*G Subj*T Subj;
lsmeans G T G*T/stderr pdiff;