<?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 IDs in any Block of 6 month period in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-IDs-in-any-Block-of-6-month-period/m-p/226175#M40685</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID     Date: mmddyy10.;
cards;
123   1/1/15
456   2/2/15
123   2/20/15
;

proc sort data=have;
by id date;
run;

data want;
set have;
by id date;
if first.id then count=1;
else count+1;
if last.id;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 18 Sep 2015 03:01:48 GMT</pubDate>
    <dc:creator>Jagadishkatam</dc:creator>
    <dc:date>2015-09-18T03:01:48Z</dc:date>
    <item>
      <title>Count IDs in any Block of 6 month period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-IDs-in-any-Block-of-6-month-period/m-p/226171#M40683</link>
      <description>&lt;P&gt;Please I need help....&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; I have one years' worth of data, I want to flag any ID that occurs more than &amp;nbsp;1 in any 6-month period from the date on the row of that ID&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Have&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; Date&lt;/P&gt;&lt;P&gt;123 &amp;nbsp; 1/1/15&lt;/P&gt;&lt;P&gt;456 &amp;nbsp; 2/2/15&lt;/P&gt;&lt;P&gt;123 &amp;nbsp; 2/20/15&lt;/P&gt;&lt;P&gt;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Want&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp; Count&lt;/P&gt;&lt;P&gt;123 &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2015 02:14:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-IDs-in-any-Block-of-6-month-period/m-p/226171#M40683</guid>
      <dc:creator>Olaade</dc:creator>
      <dc:date>2015-09-18T02:14:10Z</dc:date>
    </item>
    <item>
      <title>Re: Count IDs in any Block of 6 month period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-IDs-in-any-Block-of-6-month-period/m-p/226175#M40685</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID     Date: mmddyy10.;
cards;
123   1/1/15
456   2/2/15
123   2/20/15
;

proc sort data=have;
by id date;
run;

data want;
set have;
by id date;
if first.id then count=1;
else count+1;
if last.id;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Sep 2015 03:01:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-IDs-in-any-Block-of-6-month-period/m-p/226175#M40685</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2015-09-18T03:01:48Z</dc:date>
    </item>
    <item>
      <title>Re: Count IDs in any Block of 6 month period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-IDs-in-any-Block-of-6-month-period/m-p/226176#M40686</link>
      <description>&lt;P&gt;Group by every observation (ID, date) in a&amp;nbsp;&lt;STRONG&gt;proc SQL&lt;/STRONG&gt;&amp;nbsp;self join :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select a.id, a.date, 1 + count(b.id) as count
from have as a inner join have as b on a.id=b.id and 
    b.date &amp;gt; a.date and intck("MONTH", a.date, b.date, "C") &amp;lt; 6
group by a.id, a.date;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Sep 2015 03:03:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-IDs-in-any-Block-of-6-month-period/m-p/226176#M40686</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2015-09-18T03:03:37Z</dc:date>
    </item>
    <item>
      <title>Re: Count IDs in any Block of 6 month period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-IDs-in-any-Block-of-6-month-period/m-p/226188#M40687</link>
      <description>&lt;P&gt;I don't understand what you mean.&lt;/P&gt;&lt;P&gt;You mean ID must have 2-6 month data ?&lt;/P&gt;&lt;P&gt;What if a ID have two or more obs in one month ?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Date : mmddyy10.;
format date mmddyy10.;
cards;
123 1/1/15
456 2/2/15
123 2/20/15
;
run;
proc sql;
create table want as
&amp;nbsp;select id,count(*) as n
&amp;nbsp; from have
&amp;nbsp; &amp;nbsp; group by id having count(distinct month(date)) between 2 and 6;
quit;&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 19 Sep 2015 06:55:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-IDs-in-any-Block-of-6-month-period/m-p/226188#M40687</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2015-09-19T06:55:07Z</dc:date>
    </item>
  </channel>
</rss>

