<?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 PROC SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/639876#M190427</link>
    <description>&lt;P&gt;How would I select distinct persons per year, but only count each person once total.&lt;/P&gt;&lt;P&gt;An example of my data is:&lt;/P&gt;&lt;P&gt;ID Date&lt;BR /&gt;1 20NOV2018&lt;BR /&gt;2 06JUN2017&lt;BR /&gt;2 29JUL2011&lt;BR /&gt;3 05MAY2014&lt;BR /&gt;4 04APR2002&lt;BR /&gt;4 25APR2009&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want my output to look like:&lt;/P&gt;&lt;P&gt;Year Cnt&lt;BR /&gt;2002 1&lt;BR /&gt;2009 0&lt;BR /&gt;2011 1&lt;BR /&gt;2014 1&lt;BR /&gt;2017 0&lt;BR /&gt;2018 1&lt;/P&gt;</description>
    <pubDate>Tue, 14 Apr 2020 20:03:14 GMT</pubDate>
    <dc:creator>mar0000</dc:creator>
    <dc:date>2020-04-14T20:03:14Z</dc:date>
    <item>
      <title>PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/639876#M190427</link>
      <description>&lt;P&gt;How would I select distinct persons per year, but only count each person once total.&lt;/P&gt;&lt;P&gt;An example of my data is:&lt;/P&gt;&lt;P&gt;ID Date&lt;BR /&gt;1 20NOV2018&lt;BR /&gt;2 06JUN2017&lt;BR /&gt;2 29JUL2011&lt;BR /&gt;3 05MAY2014&lt;BR /&gt;4 04APR2002&lt;BR /&gt;4 25APR2009&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want my output to look like:&lt;/P&gt;&lt;P&gt;Year Cnt&lt;BR /&gt;2002 1&lt;BR /&gt;2009 0&lt;BR /&gt;2011 1&lt;BR /&gt;2014 1&lt;BR /&gt;2017 0&lt;BR /&gt;2018 1&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2020 20:03:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/639876#M190427</guid>
      <dc:creator>mar0000</dc:creator>
      <dc:date>2020-04-14T20:03:14Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/639909#M190436</link>
      <description>&lt;P&gt;I think you're only trying to count the person in their earliest date if I understand correctly.&amp;nbsp; I believe it would be something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data blah;
format date date9.;
input ID 1. @3 Date date9.;
datalines;
1 20NOV2018
2 06JUN2017
2 29JUL2011
3 05MAY2014
4 04APR2002
4 25APR2009
;
run;

proc sql;
    select year(date) as year,count(distinct ifn(date=min_date,id,.)) as num
        from (select *,min(date) as min_date from blah group by id) group by year;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which gives me this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 123px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/38317i439CD9C0126071AD/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I use the IFN function (IFC if ID is a character variable) to limit the IDs to the first occuring date so the patient isn't double counted (COUNT function doesn't add a missing value).&amp;nbsp; I use an inline view to calculate the minimum date for each patient since you can't nest the MIN function and the COUNT function in the same query.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Apr 2020 22:03:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL/m-p/639909#M190436</guid>
      <dc:creator>JeffMeyers</dc:creator>
      <dc:date>2020-04-14T22:03:58Z</dc:date>
    </item>
  </channel>
</rss>

