- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I want to calculate 95% CI for proportion/percentage for a dataset as the following. Original dataset a, I would like to have an output dataset b as such. I have tried some program but not sure if it was correct. Do you have different ways to calculate the 95% CI? Thanks for helping in advance.
Dataset a
Disease cases Denominator proportion
A 2 120 0.167
B 5 300 0.167
C 3 1000 0.3
D 11 500 0.2
Dataset B
Disease cases Denominator proportion CI_low CI_high
A 2 120 0.167
B 5 300 0.167
C 3 1000 0.3
D 11 500 0.2
SAS program I tried:
data b;
set a;
p=(cases/denominator);
if p=0 then CI_Low=0;
if p=1 then CI_High=1;
if p ne 0 then CI_Low=(1-betainv(.975, (Denominator-cases+1), cases));
if p ne 1 then CI_High=(1-betainv(.025, (Denominator-cases), cases+1);
run;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Here's something to get you started with using PROC FREQ for confidence intervals. Look at the documentation for details on the CI that can be calculated and options available to you. I think some of your percentages are off in your table.
The table created called CI_VALUES holds the confidence intervals, unfortunately not in the format you requested.
*Generate sample data;
data have;
input disease $ cases denominator;
cards;
A 2 120
B 5 300
C 3 1000
D 11 500
;
run;
*Expand data to fit within proc freq - may be other ways to do this;
data expand;
set have;
do i=1 to cases;
Value=1;
output;
end;
do i=1 to denominator-cases;
Value=0;
output;
end;
run;
*Sort for output;
proc sort data=expand;
by disease;
run;
*Generate CIs;ods table binomial = CI_Values;
proc freq data=expand;
by disease;
table value/binomial(level='1');
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Have you looked at PROC FREQ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Here's something to get you started with using PROC FREQ for confidence intervals. Look at the documentation for details on the CI that can be calculated and options available to you. I think some of your percentages are off in your table.
The table created called CI_VALUES holds the confidence intervals, unfortunately not in the format you requested.
*Generate sample data;
data have;
input disease $ cases denominator;
cards;
A 2 120
B 5 300
C 3 1000
D 11 500
;
run;
*Expand data to fit within proc freq - may be other ways to do this;
data expand;
set have;
do i=1 to cases;
Value=1;
output;
end;
do i=1 to denominator-cases;
Value=0;
output;
end;
run;
*Sort for output;
proc sort data=expand;
by disease;
run;
*Generate CIs;ods table binomial = CI_Values;
proc freq data=expand;
by disease;
table value/binomial(level='1');
run;