<?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: Proc SQL count problems. in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-count-problems/m-p/462655#M70405</link>
    <description>&lt;P&gt;What is it your trying to achieve?&amp;nbsp; The reason is, if you look at a table version of your data:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table tmp as
  select a.beta_3,b.estimate,a.beta_3&amp;lt;=b.Estimate as test,count(a.beta_3&amp;lt;=b.Estimate)/count(a.beta_3) as a format=best.
  from t2 a,
  t0 b
  where b.numord=3
  ;
run;&lt;/PRE&gt;
&lt;P&gt;You will see that there is 5 rows with a 0 or 1 for each beta_3&amp;lt;=estimate, and the count(beta_3) will always be 1, as there is exactly 1 per row, 0/1=0 and 1/1=1, you get a 1 out.&lt;/P&gt;</description>
    <pubDate>Wed, 16 May 2018 12:54:18 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-05-16T12:54:18Z</dc:date>
    <item>
      <title>Proc SQL count problems.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-count-problems/m-p/462645#M70404</link>
      <description>&lt;P&gt;Hello SAS users,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm running the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data t0;
input Estimate Numord;
datalines;

2447 1
42 2
10 3
-39 4
-84 5
;
run;


data t2;
input beta_3;
datalines;

19
42
10
-42
-76
;
run;

proc sql;
  select count(a.beta_3&amp;lt;=b.Estimate)/count(a.beta_3) into :z0bar
  from t2 a,
  t0 b
  where b.numord=3
  ;
run;

%put _all_;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I am expecting 0.4 for z0bar, but I am getting 1. Why?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 May 2018 12:16:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-count-problems/m-p/462645#M70404</guid>
      <dc:creator>GKati</dc:creator>
      <dc:date>2018-05-16T12:16:12Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL count problems.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-count-problems/m-p/462655#M70405</link>
      <description>&lt;P&gt;What is it your trying to achieve?&amp;nbsp; The reason is, if you look at a table version of your data:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table tmp as
  select a.beta_3,b.estimate,a.beta_3&amp;lt;=b.Estimate as test,count(a.beta_3&amp;lt;=b.Estimate)/count(a.beta_3) as a format=best.
  from t2 a,
  t0 b
  where b.numord=3
  ;
run;&lt;/PRE&gt;
&lt;P&gt;You will see that there is 5 rows with a 0 or 1 for each beta_3&amp;lt;=estimate, and the count(beta_3) will always be 1, as there is exactly 1 per row, 0/1=0 and 1/1=1, you get a 1 out.&lt;/P&gt;</description>
      <pubDate>Wed, 16 May 2018 12:54:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-count-problems/m-p/462655#M70405</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-05-16T12:54:18Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL count problems.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-count-problems/m-p/462659#M70406</link>
      <description>&lt;P&gt;I'm trying to count the number of rows in b that are &amp;lt;= the value of the variable Estimate at numord=3, as a percentage of all the rows in b.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thx.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 May 2018 13:03:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-count-problems/m-p/462659#M70406</guid>
      <dc:creator>GKati</dc:creator>
      <dc:date>2018-05-16T13:03:22Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL count problems.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-count-problems/m-p/462677#M70408</link>
      <description>&lt;P&gt;Something like (and this is verbose just to show working out):&lt;/P&gt;
&lt;PRE&gt;  create table tmp as
  select a.*,
         b.tot,
         (select count(*) from t2 where beta_3 &amp;lt;= a.estimate) as sub,
         (calculated sub / b.tot) * 100  as percent
  from  (select * from t0 where numord=3) a
  left join (select count(*) as tot from t2) b
  on    1=1;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 16 May 2018 13:20:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-count-problems/m-p/462677#M70408</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-05-16T13:20:17Z</dc:date>
    </item>
    <item>
      <title>Re: Proc SQL count problems.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-count-problems/m-p/462684#M70409</link>
      <description>&lt;P&gt;&amp;nbsp;select &lt;STRONG&gt;sum&lt;/STRONG&gt;(a.beta_3&amp;lt;=b.Estimate)/count(a.beta_3) into :z0bar&lt;/P&gt;</description>
      <pubDate>Wed, 16 May 2018 13:31:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-SQL-count-problems/m-p/462684#M70409</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-05-16T13:31:06Z</dc:date>
    </item>
  </channel>
</rss>

