Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save statgeek/0b5a3030ce83e6af50ecd03b50cb6073 to your computer and use it in GitHub Desktop.

Select an option

Save statgeek/0b5a3030ce83e6af50ecd03b50cb6073 to your computer and use it in GitHub Desktop.
Find the confidence intervals for proportions
/*This program calculates binomial percentages and confidence limits.
Howver, this has no correction methodology so the lower bound can go below 0.
In this case a different method is needed*/
*set table name to summarize;
%let dsin=sashelp.class;
*set variable name to get percentages;
%let var = sex;
*set name of output data set;
%let dsout = Want;
*get counts of each by group and the total count;
proc sql noprint;
create table _freq as
select &var., count(*) as N
from &dsin
group by &var.;
select count(*) into :Ntotal from &dsin.;
quit;
*calculate percentages and upper/lower confidence limits;
data &dsout.;
set _freq;
Ntotal=&ntotal.;
PCT = n/Ntotal;
STD = ((PCT*(1-PCT))/NTotal)**(1/2);
UL = PCT + 1.96*STD;
LL = PCT - 1.96*STD;
run;
*remove temporary tables;
proc sql noprint;
drop table _freq;
quit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment