<?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: SQL Count not counting in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SQL-Count-not-counting/m-p/608028#M176891</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;count function gives you the number of observations for the variable in the resulting dataset, no matter&lt;/P&gt;
&lt;P&gt;what particular values the variable takes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input dummy;
cards;
0
1
1
0
0
0
1
0
;
quit;

proc sql;
SELECT count(dummy) FROM have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Your condition (pta = "Yes") creates an implicit dummy variable as the one in the example above.&lt;/P&gt;
&lt;P&gt;When pta &amp;lt;&amp;gt; "Yes" the observation will be zero but will be counted anyway.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;=&amp;gt; You have to use the sum function as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt; suggests.&lt;/P&gt;</description>
    <pubDate>Thu, 28 Nov 2019 11:00:12 GMT</pubDate>
    <dc:creator>gamotte</dc:creator>
    <dc:date>2019-11-28T11:00:12Z</dc:date>
    <item>
      <title>SQL Count not counting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Count-not-counting/m-p/608019#M176888</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to use proc SQL to calculate a percentage of entries in a dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using the following code:&lt;/P&gt;&lt;PRE&gt;proc SQL;
create table percents as
select *, 
count(pta = "Yes")/count(*) as pct_pta,&lt;BR /&gt;count(pta = "Yes") as count_pta
from d1;
quit;&lt;/PRE&gt;&lt;P&gt;The count(pta = "Yes") is counting every entry in the dataset, the pta = "Yes" condition isn't working properly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The dataset has a column pta where the value is either "Yes" or missing, I tired changing it to "Yes" or "No" and 0 or 1, but still no luck.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help me out?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Nov 2019 10:35:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Count-not-counting/m-p/608019#M176888</guid>
      <dc:creator>RoddyJ</dc:creator>
      <dc:date>2019-11-28T10:35:20Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Count not counting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Count-not-counting/m-p/608021#M176889</link>
      <description>&lt;P&gt;Using your own logic, a quick fix could be this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data d1;
pta='Yes'; output;
pta='No'; output;
pta='Yes'; output;
pta='Yes'; output;
run;

proc SQL;
create table percents as
select *, 
sum(pta = "Yes")/count(*) as pct_pta,
sum(pta = "Yes") as count_pta
from d1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Nov 2019 10:37:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Count-not-counting/m-p/608021#M176889</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-11-28T10:37:53Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Count not counting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Count-not-counting/m-p/608022#M176890</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/289103"&gt;@RoddyJ&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Depending on the output you want, you can also remove&lt;FONT color="#FF00FF"&gt; *, &lt;/FONT&gt;in you code. It will output only the percentage and frequency you want.&lt;/P&gt;
&lt;P&gt;Otherwise, the method proposed by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp; will output&amp;nbsp;as many rows as input dataset with duplicate information regarding percentage and frequency.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Nov 2019 10:46:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Count-not-counting/m-p/608022#M176890</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-11-28T10:46:56Z</dc:date>
    </item>
    <item>
      <title>Re: SQL Count not counting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SQL-Count-not-counting/m-p/608028#M176891</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;count function gives you the number of observations for the variable in the resulting dataset, no matter&lt;/P&gt;
&lt;P&gt;what particular values the variable takes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input dummy;
cards;
0
1
1
0
0
0
1
0
;
quit;

proc sql;
SELECT count(dummy) FROM have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Your condition (pta = "Yes") creates an implicit dummy variable as the one in the example above.&lt;/P&gt;
&lt;P&gt;When pta &amp;lt;&amp;gt; "Yes" the observation will be zero but will be counted anyway.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;=&amp;gt; You have to use the sum function as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt; suggests.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Nov 2019 11:00:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SQL-Count-not-counting/m-p/608028#M176891</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-11-28T11:00:12Z</dc:date>
    </item>
  </channel>
</rss>

