Two-Way ANOVA Tutorial Using SAS Studio
I will introduce how to perform a Two-Way ANOVA analysis using SAS Studio. Here is the data that you have available:
Cultivar Nitrogen Block Yield
1 CV1 N0 I 99
2 CV1 N0 II 109
3 CV1 N0 III 89
4 CV1 N1 I 115
5 CV1 N1 II 142
6 CV1 N1 III 133
7 CV1 N2 I 121
8 CV1 N2 II 157
9 CV1 N2 III 142
10 CV1 N3 I 125
11 CV1 N3 II 150
12 CV1 N3 III 139
13 CV2 N0 I 82
14 CV2 N0 II 104
15 CV2 N0 III 99
16 CV2 N1 I 117
17 CV2 N1 II 125
18 CV2 N1 III 127
19 CV2 N2 I 145
20 CV2 N2 II 154
21 CV2 N2 III 154
22 CV2 N3 I 151
23 CV2 N3 II 166
24 CV2 N3 III 175
# Download the above data to Excel using R
Cultivar= rep(c("CV1","CV2"),each=12)
Nitrogen= rep(rep(c("N0","N1","N2","N3"), each=3),2)
Block= rep(c("I","II","III"),8)
Yield= c (99, 109, 89, 115, 142, 133, 121, 157, 142, 125, 150, 139, 82, 104, 99, 117, 125, 127, 145, 154, 154, 151, 166, 175)
dataA= data.frame(Cultivar,Nitrogen,Block,Yield)
install.package("writexl")
library(writexl)
write_xlsx (DataA,"C:/Users/LG/Desktop/dataA.xlsx")
# Please confirm the directory path on your computer
Upload this Excel file to SAS Studio. After uploading the Excel file to SAS Studio, create a data table named “EXP1” in My Libraries. Then, click on the EXP1 data table. Then, select the icon for generating code located at the top.
By doing so, a new tab named “Program 1” will be created, allowing you to generate the code.
Indeed, R Studio provides essential statistical modeling tools that enable you to select variables based on the model and examine statistical outcomes without the need to write code. However, in this case, I will demonstrate the process of performing ANOVA using SAS code. Let’s input the following code into the code editor and execute it.
proc glm data= DATABASE.EXP1;
class Block Cultivar Nitrogen;
model Yield= Cultivar Nitrogen Cultivar*Nitrogen / ss1 ss3;
lsmeans Cultivar Nitrogen / adjust=tukey pdiff=all alpha=0.05 cl;
quit;
I will verify the accuracy of the above results using R.
ANOVA= aov(Yield ~ Cultivar + Nitrogen + Cultivar:Nitrogen + factor(Block), data=dataA)
summary(ANOVA)