Statistical Procedures

Programming the statistical procedures from SAS
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JoyShan
Calcite | Level 5

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;

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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;

View solution in original post

2 REPLIES 2
Reeza
Super User

Have you looked at PROC FREQ?

Reeza
Super User

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;

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 19902 views
  • 1 like
  • 2 in conversation