Hi Team,
I am trying to calculate the CI intervals by using the below code, but i am not getting the same results which are generating the CI intervals by other data step code in Computation of CIs for Binomial proportions in SAS and its practical difficulties (lexjansen.com)
My code is :
ODS OUTPUT Binomial = CI14;
PROC FREQ DATA=firstx;
BY apaneln ;
TABLES avalc/BINOMIAL alpha=0.2 out=n14(rename=(count=nn));
exact binomial;
RUN;
ODS TRACE OFF;
Code from web :
data Test;
merge ntc_n Nct;
by apaneln apanel;
prob = count/N;
if prob=0 then CI_LOW=0;
if prob=1 then CI_HIGH=1;
if prob ne 0 then CI_LOW=round((1-betainv(.8,(N-count+1),count)),.0001);
if prob ne 1 then CI_HIGH=round((1-betainv(.2,(N-count),count+1)),.0001);
pct_ci = cat (round(prob,0.001),' (', round(CI_LOW,0.001), ', ', round(CI_HIGH,0.001), ')') ;
proc sort; by apaneln;
run;
Please let me know how to generate CI values by proc freq as similar above data step
Thank you,
Rajasekhar.
Hi @raja777pharma,
Just use the correct beta quantiles: The first argument of your two BETAINV function calls must be 1-a/2 and a/2, respectively, i.e., .9 and .1, not .8 and .2 with alpha=0.2.
The formula that PROC FREQ uses is given in the documentation section "Binomial Proportions.".
The following DATA step reproduces the output from PROC FREQ by manually coding the formula.
In the sashelp.class data, there are n=19 observations and n1=9 females.
PROC FREQ DATA=sashelp.class;
TABLES SEX/BINOMIAL(CL=clopperpearson) alpha=0.2;
ods select BinomialCLs;
RUN;
data Test;
alpha = 0.2;
n=19;
count=9;
prob = count/n;
if prob=0 then CI_LOW=0;
else do;
F = quantile("F", alpha/2, 2*count, 2*(n-count+1));
frac = (n-count+1) / (count*F);
CI_LOW = 1/(1 + frac);
end;
if prob=1 then CI_HIGH=1;
else do;
F = quantile("F", 1-alpha/2, 2*(count+1), 2*(n-count));
frac = (n-count) / ((count+1)*F);
CI_HIGH = 1/(1+frac);
end;
keep alpha n count prob CI_LOW CI_HIGH ;
run;
PROC PRINT;RUN;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.