<?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: Count Distinct Names for Each Quarter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-Distinct-Names-for-Each-Quarter/m-p/453383#M114560</link>
    <description>&lt;P&gt;This ought to be closer:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" color="#000080"&gt;Proc&lt;/FONT&gt;&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" color="#000080"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;create&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;table&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;MEPRS2&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;as&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;count(&lt;/FONT&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;distinct&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp; Case_Manager)&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;CM_Cnt&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;MEPRS&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;group&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Year, Qtr&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" color="#000080"&gt;quit&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 11 Apr 2018 22:11:31 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-04-11T22:11:31Z</dc:date>
    <item>
      <title>Count Distinct Names for Each Quarter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-Distinct-Names-for-Each-Quarter/m-p/453378#M114556</link>
      <description>&lt;P&gt;I know I've done this before but can't find the code. I have a table listing case managers and I want to create a variable CM_Cnt that I can use to count the number of distinct managers each quarter. I think the code looked something like that below but it ain't working.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New"&gt;Proc&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;create&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New"&gt;table&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; MEPRS2 &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;as&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; *, (&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;/count(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;distinct&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp; Case_Manager)) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; CM_Cnt &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; MEPRS&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;group&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; Year, Qtr, Case_Manager&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New"&gt;quit&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help greatly appreciated!&lt;/P&gt;</description>
      <pubDate>Wed, 11 Apr 2018 21:32:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-Distinct-Names-for-Each-Quarter/m-p/453378#M114556</guid>
      <dc:creator>BTAinRVA</dc:creator>
      <dc:date>2018-04-11T21:32:56Z</dc:date>
    </item>
    <item>
      <title>Re: Count Distinct Names for Each Quarter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-Distinct-Names-for-Each-Quarter/m-p/453383#M114560</link>
      <description>&lt;P&gt;This ought to be closer:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" color="#000080"&gt;Proc&lt;/FONT&gt;&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" color="#000080"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;create&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;table&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;MEPRS2&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;as&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;count(&lt;/FONT&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;distinct&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp; Case_Manager)&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;CM_Cnt&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;MEPRS&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;group&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT face="Courier New" color="#0000ff"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Year, Qtr&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" color="#000080"&gt;quit&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Apr 2018 22:11:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-Distinct-Names-for-Each-Quarter/m-p/453383#M114560</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-04-11T22:11:31Z</dc:date>
    </item>
    <item>
      <title>Re: Count Distinct Names for Each Quarter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-Distinct-Names-for-Each-Quarter/m-p/453427#M114579</link>
      <description>&lt;P&gt;Thanks Astounding! I'll give that a try in the morning.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 02:05:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-Distinct-Names-for-Each-Quarter/m-p/453427#M114579</guid>
      <dc:creator>BTAinRVA</dc:creator>
      <dc:date>2018-04-12T02:05:17Z</dc:date>
    </item>
    <item>
      <title>Re: Count Distinct Names for Each Quarter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-Distinct-Names-for-Each-Quarter/m-p/453526#M114608</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16672"&gt;@BTAinRVA&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;You might also want to add Year and Qtr to the select clause.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc sql;
  create table MEPRS2 as
  select Year, Qtr,count(distinct  Case_Manager) as CM_Cnt
  from MEPRS
  group by Year, Qtr
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 12 Apr 2018 12:47:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-Distinct-Names-for-Each-Quarter/m-p/453526#M114608</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-04-12T12:47:55Z</dc:date>
    </item>
    <item>
      <title>Re: Count Distinct Names for Each Quarter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-Distinct-Names-for-Each-Quarter/m-p/453540#M114618</link>
      <description>&lt;P&gt;Patrick,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the reply. That's not quite what I want. Let's say there is a case manager AdamsB who shows up 4 times in Qtr 1 2018 then I want CM_Cnt to be 0.25 for each of those four records so that it sums to 1 when I roll it up to get a count of unique case managers.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 13:24:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-Distinct-Names-for-Each-Quarter/m-p/453540#M114618</guid>
      <dc:creator>BTAinRVA</dc:creator>
      <dc:date>2018-04-12T13:24:05Z</dc:date>
    </item>
    <item>
      <title>Re: Count Distinct Names for Each Quarter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-Distinct-Names-for-Each-Quarter/m-p/453543#M114621</link>
      <description>&lt;P&gt;Now that I talked myself thru it I came up with the answer:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New"&gt;Proc&lt;/FONT&gt;&lt;/STRONG&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;create&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New"&gt;table&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; MEPRS2 &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;as&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; *, &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;/count(Case_Manager) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; CM_Cnt&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; MEPRS&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New"&gt;group&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New"&gt; Year, Qtr, Case_Manager&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New"&gt;quit&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 13:28:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-Distinct-Names-for-Each-Quarter/m-p/453543#M114621</guid>
      <dc:creator>BTAinRVA</dc:creator>
      <dc:date>2018-04-12T13:28:04Z</dc:date>
    </item>
    <item>
      <title>Re: Count Distinct Names for Each Quarter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-Distinct-Names-for-Each-Quarter/m-p/453787#M114700</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16672"&gt;@BTAinRVA&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Patrick,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for the reply. That's not quite what I want. Let's say there is a case manager AdamsB who shows up 4 times in Qtr 1 2018 then I want CM_Cnt to be 0.25 for each of those four records so that it sums to 1 when I roll it up to get a count of unique case managers.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That's what the DISTINCT in the count already does for you.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data MEPRS;
  year=2017;
  do Qtr=1,2;
    Case_Manager='A';
    output;output;output;
  end;
  stop;
run;

Proc sql;
  create table MEPRS2 as
  select Year, Qtr,count(distinct  Case_Manager) as CM_Cnt
  from MEPRS
  group by Year, Qtr
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 314px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/19765iE8CA46703236831D/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 22:55:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-Distinct-Names-for-Each-Quarter/m-p/453787#M114700</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-04-12T22:55:35Z</dc:date>
    </item>
  </channel>
</rss>

