/** Approximate Score (Agresti-Coull) Confidence Interval for a Proportion **/ /*********************************************************** Macro ac does 1 sample Agresti-Coull confidence interval for a proportion. INPUT: dataset: input data set variable: variable to be analyzed. This should take 2 values, preferably 0 and 1. The population proportion of 1's is estimated. level: confidence level OUTPUT: sample proportion and confidence interval ***********************************************************/ %macro ac(dataset,variable,level); %let alpha2=%sysevalf(1-&level); proc sort data=&dataset; by descending &variable; run; proc print;run; proc freq data=&dataset order=data; tables &variable/binomial(ac) alpha=&alpha2; ods select binomialCLs; run; %mend ac; /*********************************************************** Sample call: First submit the above macro code, then the code below. This first part reads in the LDL data from class, and converts each value to 0 (LDL increase) or 1 (LDL decrease). ***********************************************************/ data ldl; input decrease_ldl @@; decrease=(decrease_ldl>0); cards; -7.6 13.9 27.1 14.8 6.3 42.0 41.7 18.5 31.2 24.0 ; run; /*********************************************************** And this is how the macro is called to get a 95% confidence interval. ***********************************************************/ %ac(ldl,decrease,.95);