Programming the statistical procedures from SAS

How to code contrasts including an interaction

Posts: 1

How to code contrasts including an interaction

Hey @ all,

for a couple of days now I am trying to code an interaction in my "proc mixed" model but I do not succeed. I searched google and page but I am not able to translate those solutions to my problem.

My question:

How do I write the contrast statement If I want to assess the treatment effect from visit 1 to visit 6 taking into account that there is a treatment*visit interaction?


%macro LMM (Y=, M=);

proc mixed data=work.XXX order=data;

       class treatment visit;

       MODEL &Y = treatment visit treatment*visit &M /solution ddfm=satterth ;

My outcome (y) is the change in a biomarker.

Treatment has two levels (placebo vs. active treatment).

I have baseline and 5 visits (follow up visits).

And a treatment*visit interaction.

I tried different solutions but most of the time they are not estimable.

Example (gives results but must be wrong):

contrast 'XX vs placebo '        treatment 2  -2

                                          visit 0 0 0 0 0 0

                                          treatment*visit      1 0 0 0 0 1

                                                                    -1 0 0 0 0 -1  /divisor=2 cl e;

I hope someone can help me.

Thank you.


Posts: 3,839

Re: How to code contrasts including an interaction

You might want to read this paper about the LSMESTIMATE statement, which is newer and easier to use: CONTRAST and ESTIMATE Statements Made Easy: The LSMESTIMATE Statement

Respected Advisor
Posts: 2,655

Re: How to code contrasts including an interaction

One thing that will help is to get the least squares means for each treatment at each time.  Consider the following code:

proc mixed data=work.XXX order=data;

class treatment visit subjid; /* I include subjid here because of the repeated nature of the design.  The data should be sorted by treatment, subjid, visit */

model &Y= treatment visit treatment*visit &M/solution ddfm=kenwardrogers; /* This assumes that &M is a continuous covariate.  It also shifts to the Kenward-Rogers adjustment, which uses the Satterthwaite degrees of freedom but also applies an appropriate shrinkage due to the repeated measurements */
repeated visit/subject=subjid type=ar(1); /* Sets visit as a repeated factor.  The autoregressive structure assumes equal spacing in time for the visits.  Since they are indexed, this is OK, provided that the visits are very nearly the same time apart */

random intercept/subject=subjid; /* Adds a random effect of subject for autoregressive repeated measures.  See Littell et. al. J. Anim. Sci. 1998. 76:1216–1231 */

lsmeans treatment visit treatment*visit/cl; /* Estimates of means at mean of covariate */

lsmestimate treatment*visit "Treatment1 vs Treatment 2 at visit 1" -1 1  0 0  0 0  0 0  0 0  0 0,

                                        "Treatment 1 vs Treatment 2 at visit 2" 0 0  -1 1  0 0  0 0  0 0  0 0; /* More comparisons can be added.  It is a good idea to use the "comma" method rather than putting each into a separate statement, as you may wish to apply some adjustment for multiple testing as an option */

I hope this gets you started.

Steve Denham

Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation