<?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 to count distinct by two variables using proc sql in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-distinct-by-two-variables-using-proc-sql/m-p/345370#M22853</link>
    <description>&lt;P&gt;I think this is hard to achieve in a single (non nested) SQL step.&lt;/P&gt;
&lt;P&gt;What about if a person drinks beer year 1, and wine year 2?&lt;/P&gt;</description>
    <pubDate>Wed, 29 Mar 2017 13:51:08 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2017-03-29T13:51:08Z</dc:date>
    <item>
      <title>How to count distinct by two variables using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-distinct-by-two-variables-using-proc-sql/m-p/345359#M22852</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My variables: ID, year, drinks(beer or wine).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to count distinct ID by the drinks variable: only count the ID-numbers who only drank beer and those who only drank wine. If a person drank both, they should not be in any count.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql&lt;/P&gt;&lt;P&gt;create tables want as&lt;/P&gt;&lt;P&gt;select year, drinks, count(distinct ID)&lt;/P&gt;&lt;P&gt;from have&lt;/P&gt;&lt;P&gt;group by year, drinks&lt;/P&gt;&lt;P&gt;exit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This only count distinct within each drink-type: if a person has more than one beer he is only in the count once, but if he also had wine he is also in the count for wine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope someone can&amp;nbsp;help me with my problem!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2017 13:20:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-distinct-by-two-variables-using-proc-sql/m-p/345359#M22852</guid>
      <dc:creator>SLK</dc:creator>
      <dc:date>2017-03-29T13:20:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to count distinct by two variables using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-distinct-by-two-variables-using-proc-sql/m-p/345370#M22853</link>
      <description>&lt;P&gt;I think this is hard to achieve in a single (non nested) SQL step.&lt;/P&gt;
&lt;P&gt;What about if a person drinks beer year 1, and wine year 2?&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2017 13:51:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-distinct-by-two-variables-using-proc-sql/m-p/345370#M22853</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-03-29T13:51:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to count distinct by two variables using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-distinct-by-two-variables-using-proc-sql/m-p/345654#M22874</link>
      <description>&lt;P&gt;They only have to be unique per year so a person can drink beer one year and wine the other.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Mar 2017 06:01:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-distinct-by-two-variables-using-proc-sql/m-p/345654#M22874</guid>
      <dc:creator>SLK</dc:creator>
      <dc:date>2017-03-30T06:01:24Z</dc:date>
    </item>
  </channel>
</rss>

