<?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: Creating a data set with zero count by group variable in SQL in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Creating-a-data-set-with-zero-count-by-group-variable-in-SQL/m-p/406285#M67016</link>
    <description>&lt;P&gt;Get what you want with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select 
    trtpn,
    count(distinct case when a=10 then id else . end) as count
from have
group by trtpn;
select * from want;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 21 Oct 2017 18:38:15 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2017-10-21T18:38:15Z</dc:date>
    <item>
      <title>Creating a data set with zero count by group variable in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-a-data-set-with-zero-count-by-group-variable-in-SQL/m-p/406271#M67014</link>
      <description>&lt;P&gt;I am trying to create a data set using SQL&amp;nbsp; in which the count is grouped by another variable. It happens that no record meet the criteria, so I expect it to bring back zero by the group variable. For some reasons, I keep on getting zero rows.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, suppose my data is like this:&lt;/P&gt;
&lt;P&gt;data have;&lt;BR /&gt;input id a b trtpn;&lt;BR /&gt;datalines ;&lt;BR /&gt;1 2 4 1&lt;BR /&gt;2 3 5 1&lt;BR /&gt;3 4 0 2&lt;BR /&gt;4 5 1 2&lt;BR /&gt;4 2 1 3&lt;BR /&gt;3 3 4 3&lt;BR /&gt;3 5 7 3&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc sql noprint;&lt;BR /&gt;create table want as&lt;BR /&gt;select trtpn,count(distinct id) as count&lt;BR /&gt;from have&lt;BR /&gt;where a=10&lt;BR /&gt;group by trtpn;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If it's correct ,the output should look like the following:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;trtpn count&lt;BR /&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;BR /&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;Any help is appreciated.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Oct 2017 16:36:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-a-data-set-with-zero-count-by-group-variable-in-SQL/m-p/406271#M67014</guid>
      <dc:creator>SWEETSAS</dc:creator>
      <dc:date>2017-10-21T16:36:36Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a data set with zero count by group variable in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-a-data-set-with-zero-count-by-group-variable-in-SQL/m-p/406277#M67015</link>
      <description>&lt;P&gt;Pay attention:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;... from have where a=10 ...&lt;/P&gt;
&lt;P&gt;results into zero observations.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Oct 2017 17:09:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-a-data-set-with-zero-count-by-group-variable-in-SQL/m-p/406277#M67015</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-10-21T17:09:18Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a data set with zero count by group variable in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-a-data-set-with-zero-count-by-group-variable-in-SQL/m-p/406285#M67016</link>
      <description>&lt;P&gt;Get what you want with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select 
    trtpn,
    count(distinct case when a=10 then id else . end) as count
from have
group by trtpn;
select * from want;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 21 Oct 2017 18:38:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-a-data-set-with-zero-count-by-group-variable-in-SQL/m-p/406285#M67016</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-10-21T18:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a data set with zero count by group variable in SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Creating-a-data-set-with-zero-count-by-group-variable-in-SQL/m-p/406288#M67017</link>
      <description>&lt;P&gt;Many thanks! It worked.&lt;/P&gt;</description>
      <pubDate>Sat, 21 Oct 2017 18:43:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Creating-a-data-set-with-zero-count-by-group-variable-in-SQL/m-p/406288#M67017</guid>
      <dc:creator>SWEETSAS</dc:creator>
      <dc:date>2017-10-21T18:43:38Z</dc:date>
    </item>
  </channel>
</rss>

