In an earlier post, I talked about what the Power of a test is and how it interplays with sample size.  During our session we used the SAS Power and Sample Size standalone package that can be installed with the initial installation of SAS*.  But, we can also use syntax and in particular, PROC POWER and PROC GLMPOWER to calculate power or sample size of your trial as well.  This post will use the same examples as the previous post.


Example #1

We are designing an independent samples t-test to see whether males drink more milk than females.  We need a number of pieces of information to determine the power of the test.  We need the following:

  • average milk consumed by males  (used to calculate the difference between groups)
  • average milk consumed by females (used to calculate the difference between groups)
  • standard deviation of milk consumed  (measure of variation)
  • sample size

Average milk consumed by males = 8 glasses/day
Average milk consumed by females = 5 glasses/day
Standard deviation = 2
Sample size 5 males and 5 females

For independent samples t-test we will use the PROC POWER.

Proc power;
twosamplemeans test = diif
meandiff = 3
stddev = 2
npergroup = 5
power = .;

twosamplemeans specifies the analysis you are testing for – ttest in this case
Test = diff specifies that we are looking for the difference between means
meandiff = 3 the difference between the means is 3 – 8 glasses/day drunk by males subtract the 5 glasses/day drunk by females
stddev = 2 standard deviation
npergroup = 5 there were 5 males and 5 females
power = . set this is what we want SAS to calculate – the power of the ttest based on the parameters out.

Results: Still to come

Proc POWER can also be used to determine the number of observations needed for each group in order to obtain a specified Power.  If we use the above example again, set the power to 0.80, let’s see how many observations we need.  The coding to run this will be:

Proc power;
twosamplemeans test = diif
meandiff = 3
stddev = 2
npergroup = .
power = 0.80;

Notice the change?

npergroup = .   vs. npergroup = 5   AND  power = . vs.  power = 0.80

Final note on PROC POWER

In the above example we were looking for the power (and npergroup) for a trial set out as an independent t-test design.  PROC POWER can be used for the following additional designs:

  • Logistic regression
  • Multiple linear regression
  • Fisher’s z test and t test of partial correlation
  • Single binomial proportion
  • One sample t test
  • One way ANOVA
  • McNemar’s test for paired proportions
  • Paired t test
  • Two independent proportions
  • Two sample t test
  • Two survival curves
  • Two independent groups

To view syntax details on these analyses please see the SAS Support pages


So, what happens if you have a factorial design?  PROC GLMPOWER is your answer.  Let’s take a look at our second example and see how we can use PROC GLMPOWER to calculate sample size required to obtain a power of 80%.

Example #2

We are now designing an ANOVA with 2×3 factorial design.  We want to examine whether male and female dodo birds have different beek lengths when housed in a small, medium or large yard.  We were able to obtain means and a standard deviation from a study conducted in Atlantis centuries ago and now we need to know how many dodo birds we need in order to obtain a power of 80%.

Based on the paper from Atlantis we have the following means:
Males in small yard:  12
Females in small yard:  8

Males in medium yard:  21
Females in medium yard:  21

Males in large yard:  46
Females in large yard:  39

Overall standard deviation reported in the paper was:  4

First step is to create a dataset that will contain the cell means identified above.

Data atlantis;
do sex = 1 to 2;
do housing = 1 to 3;
input beek_length @@;
12      21      46
8        21      39

To calculate sample size – we need PROC GLMPOWER

Proc glmpower data=atlantis;
class sex housing;
model beek_length = sex | housing;
stddev = 4
ntotal = .
power = 0.80;

class sex housing; specifying the class variables to be used in the model
model beek_length = sex | housing; model for which we want to calculate sample size
power telling SAS that we are going to run a power analysis
stddev = 4 Standard deviation for the trial
ntotal = . specifying that we want to calculate sample size
power = 0.80; specifying the power of this design is 80%

Results: Still to come

Final note on PROC GLMPOWER

Just as with PROC POWER, PROC GLMPOWER is used for many variations.  Please check the SAS Support pages for more details and options available.

Screen Shot 2013-11-18 at 7.33.07 PM