UCLA Academic Technology Services HomeServicesClassesContactJobs
Search

SAS FAQ
How can I write an estimate statement in proc glm using a cell means model?

We will use a data set called elemapi2.sas7bdat to demonstrate. Variables mealcat and collcat are two categorical variables, both with three levels. The dependent variable is school's API index. We want to look at a simple comparison to compare group 1 vs. 2 and above of collcat when mealcat = 1. One way of doing this using proc glm with estimate statement can be the following:
proc glm data = elemapi2;
  class collcat mealcat;
  model api00 = collcat mealcat collcat*mealcat/ss3;
  estimate 'collcat 1 vs 2+ within mealcat = 1'
                      collcat 1 -.5 -.5
              collcat*mealcat 1   0   0
		             -.5  0   0
		             -.5  0   0;
run;
quit;

Another way of accomplishing the same thing, but possibly easier is to use cell means model. A cell means model estimates only one parameter for each cell and sets the intercept to 0. The cell means model is not used in general to produce an overall test of model fit, but is often used to write simpler estimate or contrast statements. So in practice, we need to write proc glm code twice, one for the model fit and one for the estimates or contrasts. In the code shown below, the first proc glm is for model fit and the second one with the estimate statement is for the estimate of simple comparison. We use the noint option in the second proc glm to specify that we are not going to estimate the intercept, therefore will estimate one parameter per cell.

proc glm data = in.elemapi2;
  class collcat mealcat;
  model api00 = collcat mealcat collcat*mealcat/ss3;
run;
quit;
proc glm data = in.elemapi2;
  class collcat mealcat;
  model api00 = collcat*mealcat/noint ss3;
  estimate 'collcat 1 vs 2+ within mealcat = 1'
              collcat*mealcat 2 0 0 -1 0 0 -1 0 0 /divisor=2;
quit;

Notice that the order of categorical variables in the class statement decides which variable is the row variable and which is the column variable. For example, in the code above, collcat will be the row variable and mealcat will be the column variable. Therefore, the simple comparison we are interested can be formulated as the following table. Writing the numbers in the table one row at a time, we can write our estimate statement as

estimate 'simple comparison'
              collcat*mealcat 1 0 0 -.5 0 0 -.5 0 0 ;

or equivalently, we can make use of the option divisor = to rewrite the statement in terms of whole numbers as shown above. 

collcat /mealcat mealcat = 1 mealcat = 2 mealcat = 3
collcat = 1 1 0 0
collcat =2 -.5 0 0
collcat = 3 -.5 0 0

If we switch the order of variables in the class statement, we will have to rewrite our estimate statement accordingly. For example, we can rewrite the above proc glm statement such as the following and it produces exactly the same result from the estimate statement, since the corresponding table is simply being transposed:
 
mealcat/collcat collcat = 1 collcat =2 collcat=3
mealcat = 1 1 -.5 -.5
mealcat = 2 0 0 0
mealcat = 3 0 0 0

proc glm data = in.elemapi2;
  class  mealcat collcat;
  model api00 = mealcat*collcat/noint ss3;
  estimate 'collcat 1 vs 2+ within mealcat = 1'
              collcat*mealcat 2 -1 -1  0 0 0 0 0 0 /divisor=2 e;
quit;

How to cite this page

Report an error on this page

UCLA Researchers are invited to our Statistical Consulting Services
We recommend others to our list of Other Resources for Statistical Computing Help
These pages are Copyrighted (c) by UCLA Academic Technology Services


The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California