3.4 - Greenhouse Example In SAS

In this section we will modify our existing program, (Lesson1 Sas Code), to run the ANOVA. (The complete code to run the analysis is in the file: Lesson3 Sas Code).

In addition to adding two procedures (proc mixed, and proc plm) we will modify the code slightly. We named our dataset “lesson 1”, but really this is the hypothetical greenhouse data. So we changed "lesson 1" in the data statement to "greenhouse".

We can also add comments within the program to explain what the different sections of code are intended for, and you can see these comments in the code shown below. (You will see that they begin with a /* and end with */.).

data greenhouse;
input fert $ Height;
Control      21
Control      19.5
Control      22.5
Control      21.5
Control      20.5
Control      21
F1      32
F1      30.5
F1      25
F1      27.5
F1      28
F1      28.6
F2      22.5
F2      26
F2      28
F2      27
F2      26.5
F2      25.2
F3      28
F3      27.5
F3      31
F3      29.5
F3      30
F3      29.2
/* Comments, ignored by SAS, can be written anywhere, but have to be
      enclosed by /* and end with */

/* We already printed out the data, and ran the summary procedure, so I
      don't want to keep running again and generating needless output.
      So I will comment out the print procedures in our old work. 
	  I can re-activate these at any time just by removing the comment enclosures */

/* proc print data=greenhouse;
title 'Raw Data for Greenhouse Data'; run;   */

/* proc summary data=greenhouse;
class fert;
var height;
output out=output1 mean=mean stderr=se;
proc print data=output1;
title 'Summary Output for Greenhouse Data'; run;
title; run; */

/* Check Settings: From Main toolbar, choose
Tools > Options > Preferences > Results
make sure HTML box is checked and listing box is not checked */

/* I want to enable the Output Delivery System Graphics package
because I will want to produce some diagnostic plots */

ods graphics on;

/* ANOVA: We will be using Proc Mixed for most of our ANOVA work. The mixed 
procedure has several options for how the solutions
for ANOVA are reached.  I am specifying the 'Method=type3'
to use ordinary least squares rather than a maximum likelihood method
for this example. This will produce the conventional (ANOVA table) output. */

proc mixed data=greenhouse method=type3 plots=all;
class fert;
model height=fert;
store abc123; /*Stores results for the next procedure (abc123 is name I give)*/
title 'ANOVA of Greenhouse Data';

ods html style=statistical sge=on;
proc plm restore=abc123; 
lsmeans fert / adjust=tukey plot=meanplot cl lines; 
/* The lsmeans statement here prints out the model fit means, performs the Tukey
      mean comparisons, and plots the data. */
ods exclude diffplot; 
run; title; run;
Note! Penn State's installation SAS 9.4 fails to produce the .png file that is necessary to edit the graph. An alternative is simply to capture the means and the mean comparison letterings and build this graph using Microsoft Excel, or get a screen capture of the graph itself and add the lettering using a graphics program.

The output from the Proc Mixed code contains the ANOVA table and is discussed in the next section. The PLM procedure creates a plot for the means with labels showing the 95% confidence interval limits but does not label the plot with the mean comparison lettering.

To do this, we need to go to the Results tab in the Explorer Window:

SAS Explorer

By clicking on + signs at the icons, we open up the Results to find the LSmeans plot.

SAS Explorer

Double click on the bottom icon this plot and it will invoke the Graphics Editor that will look like this:

SAS Graphics Editor

If you look at the toolbar you will find a small 'ab' icon. Use this and text can be superimposed on the graph using this tool:

SAS graphics editor

When you finish labeling the means with letters, I find it easiest to use a screen capture approach, such as Jing, to copy this graph to the local clipboard (on the upper right of the screen in WebApps) to transfer it to a Word document.