<?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 Calculaion of CI intervals by Clopper-Pearson exact method is used in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculaion-of-CI-intervals-by-Clopper-Pearson-exact-method-is/m-p/859329#M339525</link>
    <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;I am trying to calculate the CI intervals by using the below code, but i am not getting the same results which are generating the CI intervals by other data step code in&amp;nbsp;&lt;A href="https://www.lexjansen.com/phuse/2013/sp/SP05.pdf" target="_blank" rel="noopener"&gt;Computation of CIs for Binomial proportions in SAS and its practical difficulties (lexjansen.com)&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is :&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;ODS OUTPUT Binomial = CI14;
PROC FREQ DATA=firstx;
BY apaneln ;
TABLES avalc/BINOMIAL alpha=0.2 out=n14(rename=(count=nn));
exact binomial;
RUN;
ODS TRACE OFF;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Code from web :&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data Test;
 merge ntc_n Nct; 
 by apaneln apanel; 
 prob = count/N; 
 if   prob=0 then CI_LOW=0; 
 if   prob=1 then CI_HIGH=1; 
 if   prob ne 0 then CI_LOW=round((1-betainv(.8,(N-count+1),count)),.0001); 
 if   prob ne 1 then CI_HIGH=round((1-betainv(.2,(N-count),count+1)),.0001); 
    pct_ci = cat (round(prob,0.001),' (', round(CI_LOW,0.001), ', ', round(CI_HIGH,0.001), ')') ;

    proc sort; by apaneln; 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Please let me know how to generate CI values by proc freq as similar above data step&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Rajasekhar.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 17 Feb 2023 08:58:25 GMT</pubDate>
    <dc:creator>raja777pharma</dc:creator>
    <dc:date>2023-02-17T08:58:25Z</dc:date>
    <item>
      <title>Calculaion of CI intervals by Clopper-Pearson exact method is used</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculaion-of-CI-intervals-by-Clopper-Pearson-exact-method-is/m-p/859329#M339525</link>
      <description>&lt;P&gt;Hi Team,&lt;/P&gt;&lt;P&gt;I am trying to calculate the CI intervals by using the below code, but i am not getting the same results which are generating the CI intervals by other data step code in&amp;nbsp;&lt;A href="https://www.lexjansen.com/phuse/2013/sp/SP05.pdf" target="_blank" rel="noopener"&gt;Computation of CIs for Binomial proportions in SAS and its practical difficulties (lexjansen.com)&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code is :&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;ODS OUTPUT Binomial = CI14;
PROC FREQ DATA=firstx;
BY apaneln ;
TABLES avalc/BINOMIAL alpha=0.2 out=n14(rename=(count=nn));
exact binomial;
RUN;
ODS TRACE OFF;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Code from web :&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data Test;
 merge ntc_n Nct; 
 by apaneln apanel; 
 prob = count/N; 
 if   prob=0 then CI_LOW=0; 
 if   prob=1 then CI_HIGH=1; 
 if   prob ne 0 then CI_LOW=round((1-betainv(.8,(N-count+1),count)),.0001); 
 if   prob ne 1 then CI_HIGH=round((1-betainv(.2,(N-count),count+1)),.0001); 
    pct_ci = cat (round(prob,0.001),' (', round(CI_LOW,0.001), ', ', round(CI_HIGH,0.001), ')') ;

    proc sort; by apaneln; 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Please let me know how to generate CI values by proc freq as similar above data step&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Rajasekhar.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2023 08:58:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculaion-of-CI-intervals-by-Clopper-Pearson-exact-method-is/m-p/859329#M339525</guid>
      <dc:creator>raja777pharma</dc:creator>
      <dc:date>2023-02-17T08:58:25Z</dc:date>
    </item>
    <item>
      <title>Re: Calculaion of CI intervals by Clopper-Pearson exact method is used</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculaion-of-CI-intervals-by-Clopper-Pearson-exact-method-is/m-p/859336#M339528</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/309000"&gt;@raja777pharma&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just use the correct beta quantiles: The first argument of your two BETAINV function calls must be 1-&lt;FONT face="symbol"&gt;a&lt;/FONT&gt;&lt;STRONG&gt;/2&lt;/STRONG&gt; and &lt;FONT face="symbol"&gt;a&lt;/FONT&gt;&lt;STRONG&gt;/2&lt;/STRONG&gt;, respectively, i.e., &lt;FONT face="courier new,courier"&gt;.9&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;.1&lt;/FONT&gt;, not &lt;FONT face="courier new,courier"&gt;.8&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;.2&lt;/FONT&gt;&amp;nbsp;with&amp;nbsp;&lt;FONT face="courier new,courier"&gt;alpha=0.2&lt;/FONT&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2023 09:38:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculaion-of-CI-intervals-by-Clopper-Pearson-exact-method-is/m-p/859336#M339528</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2023-02-17T09:38:54Z</dc:date>
    </item>
    <item>
      <title>Re: Calculaion of CI intervals by Clopper-Pearson exact method is used</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculaion-of-CI-intervals-by-Clopper-Pearson-exact-method-is/m-p/859344#M339530</link>
      <description>&lt;P&gt;The formula that PROC FREQ uses is given in &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/statug/statug_freq_details37.htm" target="_self"&gt;the documentation section "Binomial Proportions."&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;The following DATA step reproduces the output from PROC FREQ by manually coding the formula.&amp;nbsp;&lt;BR /&gt;In the sashelp.class data, there are n=19 observations and n1=9 females.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
PROC FREQ DATA=sashelp.class;
   TABLES SEX/BINOMIAL(CL=clopperpearson) alpha=0.2;
   ods select BinomialCLs;
RUN;

data Test;
alpha = 0.2;
n=19;
count=9;
prob = count/n; 
if   prob=0 then CI_LOW=0; 
else do;
   F = quantile("F", alpha/2, 2*count, 2*(n-count+1));
   frac = (n-count+1) / (count*F);
   CI_LOW = 1/(1 + frac);
end;
if prob=1 then CI_HIGH=1; 
else do;
   F = quantile("F", 1-alpha/2, 2*(count+1), 2*(n-count));
   frac = (n-count) / ((count+1)*F);
   CI_HIGH = 1/(1+frac);
end;
keep alpha n count prob CI_LOW CI_HIGH ;
run;
PROC PRINT;RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2023 11:15:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculaion-of-CI-intervals-by-Clopper-Pearson-exact-method-is/m-p/859344#M339530</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2023-02-17T11:15:02Z</dc:date>
    </item>
  </channel>
</rss>

