Programming the statistical procedures from SAS

simpler way of doing hundreds of contrasts?

Reply
Senior User
Posts: 1

simpler way of doing hundreds of contrasts?

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.

Contributor
Posts: 22

Re: simpler way of doing hundreds of contrasts?

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;

SAS Super FREQ
Posts: 3,547

Re: simpler way of doing hundreds of contrasts?

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

Contributor
Posts: 22

Re: simpler way of doing hundreds of contrasts?

@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;

Ask a Question
Discussion stats
  • 3 replies
  • 187 views
  • 0 likes
  • 3 in conversation