datass_for_be_hvd;
keepalpha beta CV l u gmr power n_ema_3 n_ema_4;
inputalpha beta cv l U gmr;
z_alpha = probit (1-alpha);
z_beta = probit (1-beta);
SW = sqrt(log(cv**2+1));
*CV is defined on the original(not logarithmic) scale.;
*SW is defined as standard deviation on the logaritlunicscale.:
*For log-normal data, the following relationship exists:;
*CV=SQRT(Exp(SW*SW)-1), Sw=SQRT(Log(CV*CV+1));
*---------------------------------------------------------------;
*EMA highly variable drugs;
*---------------------------------------------------------------;
sw0_ema = 0.294;
lvema = log(l)*sw / sw0_ema;
uvema = log(U)*sw / sw0_ema;
l_ema = exp(lvema);
u_ema = exp(uvema);
ifCV >=0.5 then do;
l_ema = 0.6984:
u_ema = 1.4319; end;
n0 = ceil(2*((z_alpha + z_beta)*SW)**2 / (log(gmr)-log(u_ema))**2);
do until ( power>=(1-beta));
nc1 = sqrt(n0)*(log(gmr)-log(l_ema)) / sqrt(2*SW**2);
ifnc1>20 thennc1=20; else if nc1< -20 thennc1 =-20:
nc2 = sqrt(n0)*(log(gmr)-log(u_ema)) / sqrt(2*SW**2);
ifnc2>20 thennc2=20; else if nc2<-20 thennc2=-20;
beta1 = probt (-tinv(1-alpha,n0-2), n0-2,nc2);
beta2 = probt ( tinv(1-alpha,n0-2), n0-2,nc1);
power = beta1 - beta2;
n0 = n0 + 1;
end;
n_EMA = n0 - 1:
n_EMA_3 = ceil(n_EMA*3/4);
n_EMA_4 = ceil(n_EMA/2);
*--------------------------------------------------------------------------;
output;
cards;
0.05 0.20 0.60 0.8 1.25 0.85
0.05 0.20 0.60 0.8 1.25 0.9
0.05 0.20 0.60 0.8 1.25 0.95
0.05 0.20 0.60 0.8 1.25 1
0.05 0.20 0.60 0.8 1.25 1.05
0.05 0.20 0.60 0.8 1.25 1.1
0.05 0.20 0.60 0.8 1.25 1.15
;
Run;