/* Appendix C                                         */

   /* Code for Combination for Set-to-Zero and           */
   /* Sum-to-Zero Restrictions                           */

proc sort;by cow;
   data two;set one;
   retain last_trt;
   resid1=0;
   resid2=0;
   if period ne 1 then do;
      if last_trt=1 then resid1=1;
      if last_trt=2 then resid2=1;
      if last_trt=3 then do;
         resid1=-1;resid2=-1;
      end;
   end;
   last_trt=trt;
   drop last_trt;

title1 'Sum-to-Zero Contraints on the residual effect';
title2 'Set-to-Zero contraints on the other effects';
title3 'This corresponds to an analysis of covariance';

proc glm;class square trt cow period ;
   model milk=square cow(square) period(square)
         trt resid1 resid2/solution;
   lsmeans trt;  * Direct effects are estimable ;

   estimate 'Residu 1'     resid1 1;
   estimate 'Residu 2'     resid2 1;
   estimate 'Residu 3'     resid1 -1 resid2 -1;
   estimate 'Residu 1 - 2' resid1 1 resid2 -1;
   estimate 'Residu 1 - 3' resid1 2 resid2  1;
   estimate 'Residu 2 - 3' resid1 1 resid2  2;

   contrast 'Carryover SS' resid1 2 resid2 1, resid1 1
            resid2 2;