<?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 count distinct with conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/count-distinct-with-conditions/m-p/462215#M117636</link>
    <description>&lt;P&gt;Could you help me combine these two sql steps into one.&amp;nbsp; I want to count distinct claims for two separate conditions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; person, count(&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;distinct&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; claim) &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; dx1claimcnt&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; temp (&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=(disease1=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;))&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;group&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; person;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; person, count(&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;distinct&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; claim) &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; dx2claimcnt&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; temp (&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=(disease2=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;))&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;group&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; person;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 14 May 2018 22:34:42 GMT</pubDate>
    <dc:creator>proctice</dc:creator>
    <dc:date>2018-05-14T22:34:42Z</dc:date>
    <item>
      <title>count distinct with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-distinct-with-conditions/m-p/462215#M117636</link>
      <description>&lt;P&gt;Could you help me combine these two sql steps into one.&amp;nbsp; I want to count distinct claims for two separate conditions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; person, count(&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;distinct&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; claim) &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; dx1claimcnt&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; temp (&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=(disease1=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;))&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;group&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; person;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; person, count(&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;distinct&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; claim) &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; dx2claimcnt&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; temp (&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=(disease2=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;))&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;group&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; person;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 22:34:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-distinct-with-conditions/m-p/462215#M117636</guid>
      <dc:creator>proctice</dc:creator>
      <dc:date>2018-05-14T22:34:42Z</dc:date>
    </item>
    <item>
      <title>Re: count distinct with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-distinct-with-conditions/m-p/462217#M117638</link>
      <description>&lt;P&gt;If your variables disease1 and disease2 have values of 0, 1 or missing then this should work:&lt;/P&gt;
&lt;PRE&gt;proc sql;
   select person, sum(disease1) as dx1claimcnt, sum(disease2) as dx2claimcnt
   from temp
   group by person;
quit;&lt;/PRE&gt;
&lt;P&gt;Which is one reason to code things 0/1 to begin with. If there are any other values than those mentioned above this will not work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 22:17:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-distinct-with-conditions/m-p/462217#M117638</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-05-14T22:17:28Z</dc:date>
    </item>
    <item>
      <title>Re: count distinct with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-distinct-with-conditions/m-p/462218#M117639</link>
      <description>&lt;P&gt;Since your GROUP BY is different I'm not sure that's possible within a SQL step.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 May 2018 22:18:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-distinct-with-conditions/m-p/462218#M117639</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-05-14T22:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: count distinct with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-distinct-with-conditions/m-p/462219#M117640</link>
      <description>&lt;P&gt;CASE is how you program conditionally in SQL.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select
  person
, count(distinct case when (disease1=1) then claim end) as claimcntdx1
, count(distinct case when (disease2=1) then claim end) as claimcntdx2
from temp 
group by person
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 May 2018 22:32:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-distinct-with-conditions/m-p/462219#M117640</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-05-14T22:32:57Z</dc:date>
    </item>
    <item>
      <title>Re: count distinct with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-distinct-with-conditions/m-p/462234#M117646</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;Brilliant!&amp;nbsp; Thank you.&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;That&amp;nbsp;solution doesn't dedup the claims before counting.&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;@Reeza Fixed my typo.&amp;nbsp; Sorry tor the confusion.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 May 2018 00:49:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-distinct-with-conditions/m-p/462234#M117646</guid>
      <dc:creator>proctice</dc:creator>
      <dc:date>2018-05-15T00:49:06Z</dc:date>
    </item>
    <item>
      <title>Re: count distinct with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-distinct-with-conditions/m-p/462415#M117724</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18050"&gt;@proctice&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;Brilliant!&amp;nbsp; Thank you.&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;That&amp;nbsp;solution doesn't dedup the claims before counting.&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; Fixed my typo.&amp;nbsp; Sorry tor the confusion.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Data example of input and output would have likely&amp;nbsp;changed my suggestion. Also, I&amp;nbsp;did not "Count" anything, but summed a variable. With notes about the condition that it might work in the lack of details about your data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;As it is I could not tell whether the "group by" variable was correct (no changed) and I did not see a requirement for "dedup". Phrases like "count distinct claims for two separate conditions" are kind of imprecise without a concrete example.&lt;/P&gt;</description>
      <pubDate>Tue, 15 May 2018 16:40:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-distinct-with-conditions/m-p/462415#M117724</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-05-15T16:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: count distinct with conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/count-distinct-with-conditions/m-p/535604#M147100</link>
      <description>&lt;P&gt;Thank you! This was sooo helpful!&lt;/P&gt;</description>
      <pubDate>Thu, 14 Feb 2019 14:49:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/count-distinct-with-conditions/m-p/535604#M147100</guid>
      <dc:creator>kbelang1</dc:creator>
      <dc:date>2019-02-14T14:49:49Z</dc:date>
    </item>
  </channel>
</rss>

