This week's SAS tip on writing LSMEANS statements comes from the big spring-green book A Step-by-Step Approach to Using SAS for Univariate and Multivariate Statistics, Second Edition. Striking in appearance, this comprehensive guide by professors Norm O'Rourke, Larry Hatcher, and Edward J. Stepanski is a great resource for students, researchers, and data analysts. And it's written in a clear and unintimidating way.
If you'd like more information about this book or to view a free chapter, user reviews, or the table of contents - visit the catalog page. You can also view a previous SAS author's tip from this book on Useful PROC CORR Options.
The following excerpt is from SAS Press authors Norm O'Rourke, Larry Hatcher, and Edward J. Stepanski and their book "A Step-by-Step Approach to Using SAS for Univariate and Multivariate Statistics, Second Edition" Copyright © 2005, SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. (please note that results may vary depending on your version of SAS software)
The General Form
Below is the general form for the PROC step of a SAS program that uses the LSMEANS statement rather than the MEANS statement:
PROC GLM DATA = dataset-name; CLASS predictorA predictorB; MODEL criterion-variable = predictorA predictorB predictorA*predictorB; LSMEANS predictorA predictorB predictorA*predictorB; LSMEANS predictorA predictorB / PDIFF ADJUST=TUKEY ALPHA=alphalevel; RUN;
The preceding general form is very similar to the general form that used the MEANS statement earlier in this chapter. The primary difference is that the two MEANS statements is replaced with two LSMEANS statements. The first LSMEANS statement takes this form:
LSMEANS predictorA predictorB predictorA*predictorB;
You can see that this LSMEANS statement is identical to the earlier MEANS statement, except that “MEANS” is replaced with “LSMEANS.”
The second LSMEANS statement is a bit more complex:
LSMEANS predictorA predictorB / PDIFF ADJUST=TUKEY ALPHA=alpha-level;
You can see that this second LSMEANS statement contains a forward slash, followed by a number of keywords for options. Here is what the key words request:
- PDIFF requests that SAS print p values for significance tests related to the multiple comparison procedure. These p values tell you whether or not there are significant differences between the least-squares means for the different levels under the two predictor variables.
- ADJUST=TUKEY requests a multiple comparison adjustment for the p values and confidence limits for the differences between the least-squares means. Including ADJUST=TUKEY requests an adjustment based on the Tukey HSD test. The adjustment can also be based on other multiple-comparison procedures.
- ALPHA= specifies the significance level to be used for the multiple comparison procedure and the confidence level to be used with the confidence limits. Specifying ALPHA=0.05 requests that the significance level (alpha) be set at .05 for the Tukey tests. If you had wanted alpha set at .01, you would have used the option ALPHA=0.01, and if you had wanted alpha set at .10, you would have used the option ALPHA=0.1.