SAS CODES FOR EXPERIMENTAL DESIGNS
Completely Randomized Design (CRD)
Let us consider three treatments (A, B, C)
Step 1: Load your data
data crd;
input Treatment $ Response;
cards;
A 12
A 15
A 14
B 18
B 20
B 19
C 22
C 23
C 21
;
run;
Step 2: Perform the ANOVA for CRD
proc glm data=crd;
class Treatment;
model Response = Treatment;
means Treatment / tukey;
title "Analysis of Completely Randomized Design";
run;
Randomized Complete Block Design (RCBD)
Step 1: Load your data
data rcbd;
input Block $ Treatment $ Response;
cards;
1 A 15
1 B 18
1 C 16
2 A 17
2 B 19
2 C 18
3 A 16
3 B 17
3 C 15
4 A 19
4 B 21
4 C 20
;
run;
Step 2: Perform the ANOVA for RCBD
proc glm data=rcbd;
class Block Treatment;
model Response = Block Treatment;
means Treatment / tukey;
title "Analysis of Randomized Complete Block Design";
run;
Latin Square Design (LSD)
Step 1: Load your data
data lsd;
input Row $ Column $ Treatment $ Response;
cards;
1 1 A 10
1 2 B 15
1 3 C 14
2 1 B 12
2 2 C 18
2 3 A 13
3 1 C 11
3 2 A 16
3 3 B 19
;
run;
Step 2: Perform ANOVA using the following code
proc glm data=lsd;
class Row Column Treatment;
model Response = Row Column Treatment;
means Treatment / tukey;
title "Analysis of Latin Square Design";
run;
Split Plot Design (SPD)
/* Import the dataset */
data splitplot;
input Block A B Y;
datalines;
1 1 1 50
1 1 2 55
1 2 1 60
1 2 2 65
2 1 1 52
2 1 2 56
2 2 1 61
2 2 2 66
/* Add more data as needed */
;
run;
/* PROC MIXED for split-plot design */
proc mixed data=splitplot;
class Block A B;
model Y = A B A*B;
random Block A*Block;
lsmeans A*B / pdiff adjust=tukey;
run;
Strip Plot Design
/* Import the dataset */
data stripplot;
input Block A B Y;
cards;
1 1 1 50
1 1 2 55
1 2 1 60
1 2 2 65
2 1 1 52
2 1 2 56
2 2 1 61
2 2 2 66
/* Add more data as needed */
;
run;
/* PROC MIXED for strip-plot design */
proc mixed data=stripplot;
class Block A B;
model Y = A B A*B;
random Block A*Block B*Block;
lsmeans A*B / pdiff adjust=tukey;
run;
2 Factors Factorial Design
/* Import the dataset */
data factorial;
input A B Y;
cards;
1 1 45
1 2 50
1 3 48
2 1 55
2 2 60
2 3 58
3 1 65
3 2 70
3 3 68
/* Add more data as needed */
;
run;
/* PROC GLM for 2-factor factorial design */
proc glm data=factorial;
class A B;
model Y = A B A*B;
lsmeans A*B / pdiff=all adjust=tukey;
run;
3 Factors Factorial Design
/* Import the dataset */
data factorial3;
input A B C Y;
datalines;
1 1 1 45
1 1 2 50
1 2 1 55
1 2 2 60
2 1 1 48
2 1 2 53
2 2 1 58
2 2 2 63
3 1 1 52
3 1 2 57
3 2 1 62
3 2 2 67
/* Add more data as needed */
;
run;
/* PROC GLM for 3-factor factorial design */
proc glm data=factorial3;
class A B C;
model Y = A B C A*B A*C B*C A*B*C;
lsmeans A*B*C / pdiff=all adjust=tukey;
run;
Pooled Analysis of RBD
/* Import the dataset */
data pooled_rbd;
input Trial Block Trt Y;
datalines;
1 1 1 45
1 1 2 50
1 1 3 48
1 2 1 55
1 2 2 60
1 2 3 58
2 1 1 52
2 1 2 57
2 1 3 55
2 2 1 60
2 2 2 65
2 2 3 63
/* Add more data as needed */
;
run;
/* PROC MIXED for pooled analysis of RBD */
proc mixed data=pooled_rbd;
class Trial Block Trt;
model Y = Trt Trial Trt*Trial;
random Block(Trial);
lsmeans Trt / pdiff adjust=tukey;
run;