I want this output:
Sample Size | Desired | Success | Success Rate (%) | Lower Limit of | Upper Limit of | Actual |
120 | 1.00 | 120 | 100.00 | 96.97 | 100.00 | 1.51 |
120 | 2.50 | 119 | 99.17 | 95.44 | 99.98 | 2.27 |
120 | 3.50 | 117 | 97.50 | 92.87 | 99.48 | 3.31 |
To validate the above table, I tried the below program:
%let N=120;
data CIop;
do i=117 to &N;
retain N x p L U alpha;
p=i/&N;
alpha=0.05;
if p=0 then L=0;
if p=1 then U=1;
if p ne 0 then L=(1-betainv(1-alpha/2, &N-i+1, i));
if p ne 1 then U=betainv (1-alpha/2, i+1, &N-i);
N=&N;
x=i;
output;
end;
run;
proc print data=CIop;
var N x p L U;
run;
*
I got everything in the above table except the 'Desired CI Half Width' and 'Actual CI Half Width'.
How can i get the above complete table with Desired and Expected CI Half Width.
Thank you so much!
The 'Actual CI Half Width' is (U - L)/2.
In case anyone else wants to understand the program, the OP is calculating the exact Clopper-Pearson interval for the binomial proportion. The Clopper-Pearson estimate is used because the proportion of successes (p) is close to 1, which violates the usual scenario in which the more familiar Wald interval is applicable.
I'm still not sure what the 'Desired CI Half-Width' column is, but I think it is a "given" column that is provided for us. It looks like the task is similar to a power or sample size computation. The second column is the "target" and the other columns show the CI for the proportion that comes closest to matching this target value.
Please explain further. How can it be that the table you want has 7 columns but your PROC PRINT only mentions 5 variables?
Thank you, Paige Miller.
I don't know what should be the program i need to write for these additional two variables, Desired and Actual CI Half Width. That's why i did not put these two variable in the proc print. At that moment, pls forget the proc print part. Compare my program and the expected output table what additional program i need to write to get the output table or how differently i can write my program.
Respectfully,
How do you calculate these two values? What is the formula? (I realize you don't know how to program it in SAS, just tell us the formula for these).
The 'Actual CI Half Width' is (U - L)/2.
In case anyone else wants to understand the program, the OP is calculating the exact Clopper-Pearson interval for the binomial proportion. The Clopper-Pearson estimate is used because the proportion of successes (p) is close to 1, which violates the usual scenario in which the more familiar Wald interval is applicable.
I'm still not sure what the 'Desired CI Half-Width' column is, but I think it is a "given" column that is provided for us. It looks like the task is similar to a power or sample size computation. The second column is the "target" and the other columns show the CI for the proportion that comes closest to matching this target value.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.