<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How do I compute confidence intervals in SAS for sample proportions (percentages) in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/How-do-I-compute-confidence-intervals-in-SAS-for-sample/m-p/509539#M26121</link>
    <description>&lt;P&gt;Thank you for the advice and link.&lt;/P&gt;</description>
    <pubDate>Thu, 01 Nov 2018 14:38:01 GMT</pubDate>
    <dc:creator>Eibhlin_w</dc:creator>
    <dc:date>2018-11-01T14:38:01Z</dc:date>
    <item>
      <title>How do I compute confidence intervals in SAS for sample proportions (percentages)</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-do-I-compute-confidence-intervals-in-SAS-for-sample/m-p/509457#M26114</link>
      <description>&lt;P&gt;Hi there, I am trying to compute 95% confidence intervals of sample proportions in&amp;nbsp;SAS enterprise guide.&amp;nbsp;I&amp;nbsp;have computed overall percentages and&amp;nbsp;divided these by 100 to produce p-hat (0.0328) using proc sql. Referring to the code below, I then tried to compute&amp;nbsp;confidence intervals using the code below&amp;nbsp;but it does not compute the correct number (I have done these done correctly in excel, I should be getting .02884 but I am getting .03279 instead using the code below). Below is the lower CI, and the same problem happens for the upper CI. The 7810 below&amp;nbsp;in the code refers to&amp;nbsp;the number of my sample.&amp;nbsp;I am new to SAS so I would appreciate any help or feedback. I have heard that proc freq data could be used (the overall percentages I have computed are derived from the original data, they are percentage differences of two totalled columns) but I don't know where to begin in computing the CIS in this way, but if this was a better way to do it, I have access to the raw data. Thanks so much&amp;nbsp;in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="4"&gt;Proc&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="4"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="4"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="4"&gt;create&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="4"&gt;table&lt;/FONT&gt;&lt;FONT face="Courier New" size="4"&gt; CI &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="4"&gt;as&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="4"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="4"&gt; (p_hat-(&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="4"&gt;1.96&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="4"&gt;*SQRT(p_hat*(&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="4"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="4"&gt;-p_hat))/&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="4"&gt;7810&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="4"&gt;)) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="4"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="4"&gt; CI&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="4"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="4"&gt; P_hat_data; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="4"&gt;Quit&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="4"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2018 11:14:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-do-I-compute-confidence-intervals-in-SAS-for-sample/m-p/509457#M26114</guid>
      <dc:creator>Eibhlin_w</dc:creator>
      <dc:date>2018-11-01T11:14:47Z</dc:date>
    </item>
    <item>
      <title>Re: How do I compute confidence intervals in SAS for sample proportions (percentages)</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-do-I-compute-confidence-intervals-in-SAS-for-sample/m-p/509461#M26115</link>
      <description>&lt;P&gt;For statistical results, its not common to manually do these (in either datastep or sql).&amp;nbsp; You would use an appropriate procedure.&amp;nbsp; For an example, here is proc means used:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Statistical-Procedures/95-CI-for-means-direct-output-from-proc-means-is-different-to/td-p/356980" target="_blank"&gt;https://communities.sas.com/t5/SAS-Statistical-Procedures/95-CI-for-means-direct-output-from-proc-means-is-different-to/td-p/356980&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2018 11:21:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-do-I-compute-confidence-intervals-in-SAS-for-sample/m-p/509461#M26115</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-11-01T11:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: How do I compute confidence intervals in SAS for sample proportions (percentages)</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-do-I-compute-confidence-intervals-in-SAS-for-sample/m-p/509469#M26117</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/233379"&gt;@Eibhlin_w&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I agree that common statistics such as a CI for a proportion don't need to be computed "by hand" (i.e. in PROC SQL or a DATA step).&amp;nbsp;&lt;A href="https://documentation.sas.com/?docsetId=statug&amp;amp;docsetTarget=statug_freq_syntax.htm&amp;amp;docsetVersion=14.3&amp;amp;locale=en" target="_blank"&gt;PROC FREQ&lt;/A&gt;&amp;nbsp;offers a variety of confidence intervals for binomial proportions. Use the BINOMIAL option of the TABLES statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create test data for demonstration */

data test;
do _n_=1 to 7810;
  c=2-(_n_&amp;lt;=256);
  output;
end;
run;

/* Compute proportions and their confidence intervals */

proc freq data=test;
tables c / binomial;
run;

/* Need more decimals? Use ODS output datasets. */

ods output binomial=bin;
proc freq data=test;
tables c / binomial;
run;

proc print data=bin;
format nvalue1 12.10;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;PROC FREQ:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;The FREQ Procedure

                              Cumulative    Cumulative
c    Frequency     Percent     Frequency      Percent
------------------------------------------------------
1         256        3.28           256         3.28
2        7554       96.72          7810       100.00


      Binomial Proportion
             c = 1

Proportion                0.0328
ASE                       0.0020
95% Lower Conf Limit      0.0288
95% Upper Conf Limit      0.0367

Exact Conf Limits
95% Lower Conf Limit      0.0289
95% Upper Conf Limit      0.0370&lt;/PRE&gt;
&lt;P&gt;PROC PRINT (using ODS output from PROC FREQ):&lt;/P&gt;
&lt;PRE&gt;Obs     Table     Name1     Label1                  Value1         nValue1

 1     Table c    _BIN_     Proportion              0.0328    0.0327784891
 2     Table c    E_BIN     ASE                     0.0020    0.0020147999
 3     Table c    L_BIN     95% Lower Conf Limit    0.0288    0.0288295539
 4     Table c    U_BIN     95% Upper Conf Limit    0.0367    0.0367274244
 5     Table c                                                 .
 6     Table c              Exact Conf Limits                  .
 7     Table c    XL_BIN    95% Lower Conf Limit    0.0289    0.0289407165
 8     Table c    XU_BIN    95% Upper Conf Limit    0.0370    0.0369698724&lt;/PRE&gt;
&lt;P&gt;As you see, you get both approximate (Wald) confidence limits using the normal approximation [0.0288, 0.0367] and exact (Clopper-Pearson) confidence limits [0.0289, 0.0370]. With the CL= suboption of the BINOMIAL option you can request even more types of confidence intervals (e.g. Agresti-Coull or Wilson), see &lt;A href="https://documentation.sas.com/?docsetId=statug&amp;amp;docsetTarget=statug_freq_syntax08.htm&amp;amp;docsetVersion=14.3&amp;amp;locale=en#statug.freq.freqbinomial" target="_self"&gt;documentation&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the formula (for the lower Wald confidence limit) you used in your PROC SQL step is incorrect: The denominator 7810 must be part of the argument of the SQRT function. Here is the correct formula:&lt;/P&gt;
&lt;PRE&gt;p_hat-1.96*SQRT(p_hat*(1-p_hat)/7810)&lt;/PRE&gt;
&lt;P&gt;Edit: SAS has also various functions for computing quantiles, so you don't need to hardcode them ("1.96"):&lt;/P&gt;
&lt;PRE&gt;p_hat-probit(0.975)*SQRT(p_hat*(1-p_hat)/7810)&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2018 13:12:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-do-I-compute-confidence-intervals-in-SAS-for-sample/m-p/509469#M26117</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-11-01T13:12:26Z</dc:date>
    </item>
    <item>
      <title>Re: How do I compute confidence intervals in SAS for sample proportions (percentages)</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-do-I-compute-confidence-intervals-in-SAS-for-sample/m-p/509539#M26121</link>
      <description>&lt;P&gt;Thank you for the advice and link.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2018 14:38:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-do-I-compute-confidence-intervals-in-SAS-for-sample/m-p/509539#M26121</guid>
      <dc:creator>Eibhlin_w</dc:creator>
      <dc:date>2018-11-01T14:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: How do I compute confidence intervals in SAS for sample proportions (percentages)</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/How-do-I-compute-confidence-intervals-in-SAS-for-sample/m-p/509542#M26122</link>
      <description>&lt;P&gt;Hi &lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733" target="_self"&gt;&lt;SPAN class="login-bold"&gt;FreelanceReinhard&lt;/SPAN&gt;&lt;/A&gt;, thank you so much for the example of code and output, it's really appreciated.&amp;nbsp;The proc freq worked for me and when I ran the solution you changed that worked too! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Nov 2018 14:42:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/How-do-I-compute-confidence-intervals-in-SAS-for-sample/m-p/509542#M26122</guid>
      <dc:creator>Eibhlin_w</dc:creator>
      <dc:date>2018-11-01T14:42:43Z</dc:date>
    </item>
  </channel>
</rss>

