options ps=65 ls=65;
*This is POWERT2.PILOT.STATISTICS.SAS;
*Three files are read into this program. The first is
read into correl and contains scores on p variables. The
correlation matrix is calculated from these data. The
second is read into ds and contains effect sizes on the
same three variables. The third is read into param and
contains the minimum sample size to be considered for the
study, the maximum sample size to be considered for the
study, alpha, and the target power.;
data correl;
input var1-var3;
datalines;
1 6 3
2 7 3
3 7 1
9 4 4
6 6 5
6 4 3
3 9 6
4 9 7
5 4 3
4 10 8
1 8 4
0 6 0
2 8 3
2 3 0
6 7 5
1 10 4
3 9 3
1 11 6
5 8 3
0 7 2
proc corr data=correl outp=rs;
var var1-var3;
data ds;
input d1-d3;
datalines;
.5 .5 .2
data param;
input minn maxn alpha tpower;
datalines;
2 200 .05 .80
proc iml;
edit rs;
delete point {1 2 3};
purge;
read all into r;
print r;
edit ds;
read all into d;
print d;
edit param;
read all into temp1;
minn=temp1[1,1];
maxn=temp1[1,2];
prob=1-temp1[1,3];
target = temp1[1,4];
p=nrow(r);
ptest=ncol(d);
if p ^= ptest then do;
print ' ERROR
'
print 'number of effect sizes and number of variables are not
equal';
minn=maxn + 1;
end;
if minn <= p+1 then minn = p+2;
do n=minn to maxn;
DF2 = N + N - P -1;
nc=(n/2)*d*inv(r)*d`;
cval=FINV(prob,P,DF2);
POWER = 1 - PROBF(cval,P,DF2,NC);
if n=maxn then do; if power < target then do;
print 'Sample too small, raise maximum size';
print n nc cval power;
end;
end;
if power > target then do;
print 'Power calculations have been completed';
print n nc cval power;
print 'Note. N is the reqired number of Ss in each treatment';
n=maxn;
end;
end;
quit;