To build, somewhat, on your post from yesterday, try using PROC FCMP proc fcmp;
subroutine Binomial_p(r, n, alpha, upper6, lower6);
outargs upper6, lower6;
p = r/n;
q = 1 - p;
z = probit(1-alpha/2);
if r = 0 then do;
lower6 = 0;
upper6 = 1 - alpha**(1/n);
end;
else if r = n then do;
lower6 = alpha**(1/n);
upper6 = 1;
end;
else do;
length max_idx min_idx rc j a2 8;
max_idx = alpha/2;
min_idx = 1 - alpha/2;
declare hash h(ordered:'d');
declare hiter hi('h');
rc = h.definekey('j');
rc = h.definedata('a2');
rc = h.definedone();
do j = 0.000001 to 0.999999 by 0.00001;
if (r > 0 and r < n) then do;
a2 = 0.5*probbnml(j,n,r-1) + 0.5*probbnml(j,n,r);
if a2 <= a2 > max_idx then rc = h.add();
end;
end;
rc = hi.first();
if a2 > max_idx then upper6 = j;
rc = hi.last();
if a2 <= min_idx then lower6 = j;
end;
endsub;
function CI_Proportion(r, n, method $, alpha) $;
p = r/n;
q = 1 - p;
z = probit(1-alpha/2);
length upper lower 8;
if method = "Binomial_p" then call Binomial_p(r,n,alpha,upper,lower);
ci = strip(put(r,10.)) || " " || strip(put(p,10.4)) || "(" || strip(put(lower,10.4)) || "-" || strip(put(upper,10.4)) || ")";
return(ci);
endsub;
ci_proportion = CI_Proportion(81,263,"Binomial_p",0.05);
put ci_proportion=;
quit;
... View more