/* grapefruit2.sas */ title "Oneway ANOVA with repeated measures: Covariance Structure Approach"; title2 'Grapefruit data (Applied linear statistical models, 5th ed., Prob 27.6)'; data grape1; infile '/home/u1407221/441s24/data/grapefruit1.data.txt' firstobs=2; input store sales1-sales3; proc print data=grape1; run; data grape2; /* This data set will have 3n cases. */ set grape1; price = 1; sales = sales1; output; /* Output creates a new case. */ price = 2; sales = sales2; output; price = 3; sales = sales3; output; /* Would keep store price sales; */ proc print data=grape2; title3 'Data set with one case per observation'; run; /* It's better to use arrays */ data grape3; set grape1; array s{3} sales1-sales3; do j = 1 to 3; price = j; sales = s{j}; output; end; drop j sales1-sales3; proc print data=grape3; run; proc glm data = grape3 plots=none; title3 'Brain dead between cases analysis'; class price; model sales=price; lsmeans price / pdiff tdiff adjust = bon; proc mixed data=grape3; title3 'Proc mixed with unknown covariance structure and lsmeans'; title4 'Compare F = 29.66, p = 0.0008'; class price; model sales = price; repeated / type=un subject=store r; lsmeans price / pdiff tdiff adjust = bon; /* Gives exactly pairwise matched t-tests in this case. */ proc mixed data=grape3; title3 'Proc mixed with compound symmetry cov. structure and contrasts'; title4 'Compare F = 49.35, p < 0.0001'; class price; model sales = price; contrast '1vs2' price 1 -1 0; contrast '1vs3' price 1 0 -1; contrast '2vs3' price 0 1 -1; repeated / type=cs subject=store r; run; quit;