Least Squares Means (LSMEANS) are just one of those outputs we all love to see in our SAS output. We’ve worked through the challenges of seeing the same standard error for all our means (remember it’s based on the model and NOT the individual values) and we’ve learned how to use the PDMIX800 macro for our Proc MIXED syntax to provide us with the classic A,B,C,etc… superscripts so we don’t have to read through all those comparisons. See the code below and associated output to refresh your memory 🙂
SAS code to read in sample data and to conduct the analysis using Proc MIXED:
* Reading data gathered from a Randomized Complete Block Design conducted ;
* across 4 blocks with 6 treatments from Kuehl (2000);
Data rcbd;
input block trmt Nitrogen;
datalines;
1 1 34.98
1 2 40.89
1 3 42.07
1 4 37.18
1 5 37.99
1 6 34.89
2 1 41.22
2 2 46.69
2 3 49.42
2 4 45.85
2 5 41.99
2 6 50.15
3 1 36.94
3 2 46.65
3 3 52.68
3 4 40.23
3 5 37.61
3 6 44.57
4 1 39.97
4 2 41.9
4 3 42.91
4 4 39.2
4 5 40.45
4 6 43.29
;
Run;
/* Proc MIXED Statements with an LSMEANS for treatment differences */
Proc mixed data=rcbd;
class block trmt;
model Nitrogen = trmt;
random block;
title “Proc MIXED Results”;
lsmeans trmt / pdiff adjust=tukey;
ods output diffs=ppp lsmeans=mmm;
ods listing exclude diffs lsmeans;
Run;
%include ‘C:\Users\edwardsm\Documents\SAS_Macros\pdmix800.sas’;
%pdmix800(ppp,mmm,alpha=.01,sort=yes);
Run;
Proc GLIMMIX has a few new options available in the LSMEANS statement. The one I would like to introduce is the LINES option. You no longer need to add the PDMIX800 macro to your SAS coding, adding the LINES option at the end of your LSMEANS statement will do the same thing. Here is the SAS code for the Proc GLIMMIX for the same data and example listed above:
/* Proc GLIMMIX Statements with an LSMEANS for treatment differences */
Proc glimmix data=rcbd;
class block trmt;
model Nitrogen = trmt;
random block;
title “Proc GLIMMIX Results”;
lsmeans trmt / pdiff adjust=tukey lines;
Run;
There are a few differences in the output that you may notice. First and foremost, the results are identical for both the Proc MIXED and Proc GLIMMIX analyses. However, the output tables may appear a little different. In my opinion, the Proc GLIMMIX results are smaller, more compact. Upon close examination though, everything you need is there! The Tukey-Kramer Grouping table from the GLIMMIX (LINES option in the LSMEANS statement) does not contain the standard error for each of the lsmeans, however, if you scroll up 2 tables, you will see the same lsmeans and their associated standard errors are listed in the trmt Least Squares Means table.
All in all – same results in a more concise and cleaner format – and a few lines of less code!