I am attempting to finalize the code below, but unfortunately the r1 value is maxing out at 16 while the r value is maxing out at 18.
There seems to be some issue with the way I am looping through n1, n, r1 and r, but I am unable to identify the issue.
Code:
%MACRO s(
p0=,
p1=,
alpha=,
beta=,
usern=
);
data s_designs;
keep P0_s P1_s n_s n1_s n2_s r1_s r_s ESS_s PET_s;
do n = 2 to &usern;
do n1 = 1 to (n - 1);
n2 = n - n1;
do r1 = 0 to n1;
PET_P0 = cdf('BINOMIAL', r1, &p0, n1);
PET_P1 = cdf('BINOMIAL', r1, &p1, n1);
do r = (r1+1) to &usern;
P0_s = 1 - cdf('BINOMIAL', r, &p0, n);
P1_s = 1 - cdf('BINOMIAL', r, &p1, n);
do l = (r1 + 1) to min(n1, r);
if r - l > 0 and n - r > 0 then do;
add_P0 = pdf('BINOMIAL', l, &p0, n1) * cdf('BINOMIAL', r - l, &p0, n2);
add_P1 = pdf('BINOMIAL', l, &p1, n1) * cdf('BINOMIAL', r - l, &p1, n2);
if P0_s <= &alpha and P1_s >= 1 - &beta then do;
n_s = n;
n1_s = n1;
n2_s = n2;
r1_s = r1;
r_s = r;
PET_s = PET_P0;
ESS_s = n * PET_P0 + n1 * (1 - PET_P0);
output;
end;
end;
end;
end;
end;
end;
end;
run;
%MEND s;
%s(
p0 = 0.3,
p1 = 0.5,
alpha = 0.1,
beta = 0.1,
usern = 46
);
The code is generally operating correctly except the looping iterators are not ranging from the minimum to maximum values.
In this example, r should span from 0 to 46, r1 from r1+1 to n1, and n1 from 1 to n-1.
Any insight would be greatly appreciated.