/* Illustrates power calculations in SAS proc glmpower for general linear hypotheses. Author: S. Lohr, October 2009 */ /* Start with a two-sample t test */ /* First give SAS an exemplary data set with the group means under the alternative. */ data mytpower; input group expmean; datalines; 1 5 2 -5 ; proc glmpower data=mytpower; class group; model expmean = group; power power = . /* Missing value tells SAS this is what to calculate */ alpha = 0.05 ntotal = 16 /* Need to give total sample size for all groups */ stddev = 10; run; /* Now let's try it to calculate sample size. */ proc glmpower data=mytpower; class group; model expmean = group; power power = 0.95 alpha = 0.05 ntotal = . /* Missing value tells SAS this is what to calculate */ stddev = 10; run; /* Let's do the same thing, now with a plot of sample size needed for various powers. I strongly recommend using the plot with clients so they can see alternative scenarios. */ proc glmpower data=mytpower; class group; model expmean = group; power power = 0.95 alpha = 0.05 ntotal = . /* Missing value tells SAS this is what to calculate */ stddev = 10; plot x = power min=0.20 max = 0.99; run; /* Example on page 717 of Kutner et al, 5th edition (Kenton foods) */ /* We can do unbalanced designs in SAS by using weight variable */ data kenton; input tmt expmean ssweight; datalines; 1 12.5 2 2 13 3 3 18 3 4 21 2 ; proc glmpower data=kenton; class tmt; model expmean = tmt; weight ssweight; power power = . alpha = 0.05 ntotal = 10 stddev = 2.5; run; /* Calculate sample size using this design. Note that with unbalanced design, SAS gives fractional observations. */ proc glmpower data=kenton; class tmt; model expmean = tmt; weight ssweight; power power = .95 alpha = 0.05 ntotal = . stddev = 2.5; run;