options ls=80 ps=65 nocenter; title1 'Box-Cox Example'; /* Read in data set and take log of each response. We will use the average of the log values to compute the geometric mean */ data one; infile 'c:\saswork\data\boxcox.dat'; input trt resp; logresp = log(resp); /* This is computing the average of the log values.*/ proc univariate data=one noprint; var logresp; output out=two mean=mlogresp; /* By taking the antilog of the mean log value, we get the geometric mean. This then runs through values of lambda ranging between -1 and 1 (with a special computation when l=0) computing the "transformed" value of each response. */ data three; set one; if _n_ eq 1 then set two; ydot = exp(mlogresp); do l=-1.0 to 1.0 by .25; den = l*ydot**(l-1); if l eq 0 then den = 1; yl=(resp**l -1)/den; if l=0 then yl=ydot*log(resp); output; end; keep trt yl l; /* We now run GLM for each value of l outputing certain summary info into a data set called "four". All we really need is the value of l and the residual SS */ proc sort data=three out=three; by l; proc glm data=three noprint outstat=four; class trt; model yl=trt; by l; /* This throws everything else away except for l and the residual SS */ data five; set four; if _SOURCE_ eq 'ERROR'; keep l SS; symbol1 v=circle i=sm50; proc gplot; plot SS*l; run;