## Confidence intervals for Proportions

Solved
Occasional Contributor
Posts: 14

# Confidence intervals for Proportions

Hello, Does Enterprise Guide provide a way to calculate confidence intervals for proportions without having to write your own code? The formula I am referring to is: p +- 1.96*SQRT(p(-1p)/n) If there is no way to write this without code, does anyone have a reference to, or is able to write some code that calculates that nicely? I am also interested to hear how both a point-and-click, and code method deals with non-response. Thank you

Accepted Solutions
Solution
‎08-26-2014 11:44 PM
Posts: 1,270

## Re: Confidence intervals for Proportions

Try proc surveyfreq

All Replies
Super User
Posts: 10,850

## Re: Confidence intervals for Proportions

Check proc freq;

```
proc freq data=sashelp.class order=freq;
tables sex/binomial(ac wilson exact) alpha=.1;
run;

```

Xia Keshan

Posts: 2,127

## Re: Confidence intervals for Proportions

SAS/STAT(R) 13.1 User's Guide

shows how to incorporate them.

As far as missing, how you address it depends on how it occurred.  MCAR can generally be ignored, the missing data can be assumed to have equal impact on all groups.  In those cases, your effective sample size is the non-missing observations.  If the reason for the missing is known (MNAR), then you can incorporate that as a separate category in any statistical test.  Alternately, for both MAR and MNAR, you can use PROC MCMC to actually model the process.  The MCMC documentation has a good discussion of missingness ( SAS/STAT(R) 13.1 User's Guide ),

Occasional Contributor
Posts: 14

## Re: Confidence intervals for Proportions

Hi All again,

@Ksharp - I am looking for the confidence intervals of frequencies, not just the mean

@Doc@Duke - I couldnt seem to see an example of a confidence interval for frequencies in your links either sorry.

Based on this - http://www2.sas.com/proceedings/sugi25/25/btu/25p069.pdf (p4) I have edit some code of my own to try and acomplish my outcome of confidence intervals for frequencies.

This code attempts to calculate 95% confidence intervals for QE5AM_Recode, with frequency being a sum of the WT variable. I am an amature coder so it is probably very bad code. Also, it still outputs the first table and I dont want it too. Lastly, I have to enter the n value for the confidence interval calculation (in this case the sum of WT) manually. Ideally, this value would be calculted automatically based on the dataset that was entered.

Is anyone able to help make this more elagent?

Kind Regards

*Calculate Weighted Counts from raw dataset;

PROC TABULATE

OUT = test;

VAR WT;

CLASS QE5AM_Recode / MISSING;

TABLE /* Row Dimension */QE5AM_Recode,

/* Column Dimension */WT*(Sum);

RUN;

*Drop unwanted variables;

DATA test_ii;

set test;

drop _TYPE_ _PAGE_ _TABLE_ WT_N;

RUN;

*Frequency to calculate Percentage;

proc freq data=test_ii noprint;

weight WT_sum;

tables QE5AM_Recode / nocum out=test_iii;

run;

data test_iv; set test_iii ;

P = PERCENT/100 ;

N = 2539;

LB = P - ( 1.96*SQRT( P*(1-P)/N ) ) ;

* reset lower bound to 0 if <0 ;

IF LB < 0 THEN LB = 0 ;

UB = P + ( 1.96*SQRT( P*(1-P)/N ) ) ;

* reset upper bound to 1 if >1 ;

IF UB > 1 Then UB = 1 ;

label p = ’Proportion Cured’

LB = ’Lower Bound’

UB = ’Upper Bound’ ;

run;

*Print Results;

Proc Print data=test_iv;

run;

Super User
Posts: 4,025

## Re: Confidence intervals for Proportions

Have you looked at PROC UNIVARIATE?

It can do confidence intervals like this example: http://support.sas.com/documentation/cdl/en/procstat/67528/HTML/default/viewer.htm#procstat_univaria...

Perhaps with a bit of tweaking it can do what you want.

Occasional Contributor
Posts: 14

## Re: Confidence intervals for Proportions

The table in your link does look really close to what I'm looking for. The only problem is that instead of producing confidence intervals for the various quantiles, I want it for proportions from a frequency. I tried to change it to do this, but didn't really get anywhere. Are you able to help?

regards,

Super User
Posts: 4,025

## Re: Confidence intervals for Proportions

Unfortunately I haven't explored UNIVARIATE enough to give you a better answer.

However there is another example that does frequency counts:

http://support.sas.com/documentation/cdl/en/procstat/67528/HTML/default/viewer.htm#procstat_univaria...

Does this give you enough to at least get your frequencies? If so can you try the other example's options on top?

Occasional Contributor
Posts: 14

## Re: Confidence intervals for Proportions

Thanks again for your efforts SASKiwi - unfortunatly the earlier option for confidence intervals just produces a seperate table with the quantiles. Any more ideas?

Super User
Posts: 4,025

## Re: Confidence intervals for Proportions

Have a look here at all of the options under confidence intervals.

http://support.sas.com/kb/30/333.html

Solution
‎08-26-2014 11:44 PM
Posts: 1,270

## Re: Confidence intervals for Proportions

Try proc surveyfreq

Occasional Contributor
Posts: 14

## Re: Confidence intervals for Proportions

Thank you all for your help. PROC SURVEYFREQ is what I was after.

🔒 This topic is solved and locked.

Discussion stats
• 10 replies
• 2842 views
• 0 likes
• 5 in conversation