BookmarkSubscribeRSS Feed
funda
Calcite | Level 5

Hi All,

I have a dataset with 51 genotypes and 2 treatments.


I fit a model with proc mixed as

proc mixed data=data  ;
class treatment genotype ;
model trait = treatment genotype treatment*genotype / htype=1 ddfm=satterth  ;

lsmestimate treatment*genotype '(geno1-geno2)trt1 vs (geno1-geno2)trt2' 1 -1  0  0  0  0  0  0  0  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
                                                           -1  1  0  0  0  0  0  0  0  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0;

lsmestimate treatment*genotype '(geno1-geno3)trt1 vs (geno1-geno3)trt2' 1  0 -1  0  0  0  0  0  0  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0
                                                           -1  0  1  0  0  0  0  0  0  0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0   0;
 
run;

I would like to compare the difference between one genotype with the rest of the genotypes in treatment1  and the difference between one genotype with the rest of the genotypes in treatment2

 

                              Ho: (geno1 - geno2)treatment1 = (geno1 - geno2)treatment2

 

Is there any way to do this without having to write hundreds of individual constrasts?


Thanks.

3 REPLIES 3
sschleede
Obsidian | Level 7

I was trying to think how to create a macro variable for your contrasts. I came up with this code to create all the different contrasts (change 4 to 100 to see how it would work with your example). But, I haven't figured out a way to either 1) use the contrast variable in this dataset as a macro variable for your model statement or 2) put this code outside of a datastep. I don't think arrays can be used outside a datastep.

 

data test;

     length Contrast $ 300;

     array a{4} a1 - a4;

     /* Initialize array */

     do x = 1 to 4;

          a{x} = 0;

     end;

     Contrast = '';

/* This loop will cycle through the array. i controls the +1, j controls the -1. */

/* Contrast will have 12 unique contrasts for the model */

     do i = 1 to 4;

        a{i} = 1;

        do j = 1 to 4;

           if i ^= j then do;

              a{j} = -1;

              do y = 1 to 4;

                 Contrast = catx(' ',Contrast,a{y});

              end;

              output;

              Contrast = '';

              a{j} = 0;

            end;

         end;

         a{i} = 0;

     end;

     keep Contrast;

run;

Rick_SAS
SAS Super FREQ

@sschleede You can use CALL EXECUTE to call the procedure and pass in the constrasts.

sschleede
Obsidian | Level 7

@Rick_SAS Thank you! I will find the CALL EXECUTE very helpful in my work!

 

Below is my code of how to do the proc mixed call. I don't know if you wanted all combinations (e.g. 1 -1 0 0 and -1 1 0 0) or just one (e.g. only -1 1 0 0). If you make it do j = i+1 to 4, then you will get only 1 combination.

You can run this even if you don't have a dataset and see the code it writes for SAS to execute.

 

data test;
     length Contrast $ 300;
     array a{4} a1 - a4;
     /* Initialize array */
     do x = 1 to 4;
          a{x} = 0;
     end;
     Contrast = '';
/* This loop will cycle through the array. i controls the +1, j controls the -1. */
/* Contrast will have 12 unique contrasts for the model */
     do i = 1 to 4;
        a{i} = 1;
        do j = 1 to 4;
           if i ^= j then do;
              a{j} = -1;
              do y = 1 to 4;
                 Contrast = catx(' ',Contrast,a{y});
              end;
             call execute (
                   "proc mixed data=data1  ; "    ||
                   "   class treatment genotype ;"   ||
                   " model trait = treatment genotype treatment*genotype / htype=1 ddfm=satterth  ;" ||
                   " lsmestimate treatment*genotype '(geno1-geno2)trt1 vs (geno1-geno2)trt2' " ||
                   Contrast || ";")
              ;
              output;
              Contrast = '';
              a{j} = 0;
            end;
         end;
         a{i} = 0;
     end;
     keep Contrast;
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1306 views
  • 0 likes
  • 3 in conversation