/***************************************************************/
/*          s a s   s a m p l e   l i b r a r y                */
/*                                                             */
/*    name: friedman                                           */
/*   title: two-way nonparametric anova                        */
/* product: stat                                               */
/*  system: all                                                */
/*    keys: anova nonpar                                       */
/*   procs: glm rank                                           */
/*    data:                                                    */
/*                                                             */
/* support:                             update:                */
/*     ref:                                                    */
/*    misc:                                                    */
/*                                                             */
/***************************************************************/
*-----------------------------friedman-------------------------*
*  friedman's two-way nonparametric anova can be calculated by *
*  using the glm procedure in conjunction with the rank        *
*  procedure done by the blocking variable.  to calculate the  *
*  chi-square, multiply the sum-of-squares for treatment by    *
*  12 /((t*(t+1)) where t is the number of treatments          *
*--------------------------------------------------------------*;

title 'randomized complete block design';

data;
   input block trtment $ yield;
   cards;
1 a 32.6
1 b 36.4
1 c 29.5
1 d 29.4
2 a 42.7
2 b 47.1
2 c 32.9
2 d 40.0
3 a 35.3
3 b 40.1
3 c 33.6
3 d 35.0
4 a 35.2
4 b 40.3
4 c 35.7
4 d 40.0
5 a 33.2
5 b 34.3
5 c 33.2
5 d 34.0
6 a 33.1
6 b 34.4
6 c 33.1
6 d 34.1
;
proc rank;
   by block;
   var yield;
   ranks ryield;
   run;
proc print;
   title2 'original and ranked values of yield';
   run;
proc glm; classes block trtment;
   model ryield = block trtment;
   means trtment/lsd;
   title2 'friedman''s two-way non-parametric anova';
   run;