<?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: Find ids with at least two events that are less than 12 months apart in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-ids-with-at-least-two-events-that-are-less-than-12-months/m-p/281358#M57045</link>
    <description>&lt;P&gt;If the aforementioned discrepancy was just a typo, this might be a solution:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id event_date :mmddyy10.;
format event_date mmddyy10.;
cards;
1 1/1/2005
1 2/21/2007
1 2/22/2007
1 12/5/2004
2 1/1/2004
2 3/3/2007
2 7/5/2005
3 11/2/2004
3 1/5/2005
;
run;

proc sort data=have;
by id event_date;
run;

data want (keep=id);
set have;
by id;
retain flag;
prev_date = lag(event_date);
if first.id then flag = 0;
else do;
  if intck('month',prev_date,event_date,'cont') &amp;lt;= 12 then flag = 1;
end;
if last.id and flag then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 30 Jun 2016 07:27:58 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2016-06-30T07:27:58Z</dc:date>
    <item>
      <title>Find ids with at least two events that are less than 12 months apart</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-ids-with-at-least-two-events-that-are-less-than-12-months/m-p/281330#M57030</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I have a dataset with the ID and event date for each id. Each id can have many events up to 40 event dates. I want to find id who have at least 2 events that happened within no more than 12 months from each other. In the case below, the new dataset should keep id 1 and 3 because both have at least 2 even dates that are less than 12 months from each other&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;id     event_Date
1      1/1/2005
1      2/21/2007
1      2/22/2007
1     12/5/2004
2     1/1/2004
2     3/3/2007
2     7/5/2006
3    11/2/2004
3     1/5/2005&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Jun 2016 04:04:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-ids-with-at-least-two-events-that-are-less-than-12-months/m-p/281330#M57030</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-06-30T04:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: Find ids with at least two events that are less than 12 months apart</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-ids-with-at-least-two-events-that-are-less-than-12-months/m-p/281353#M57042</link>
      <description>&lt;P&gt;But as your logic , 2 should be include too.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2 3/3/2007&lt;BR /&gt;2 7/5/2006&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;only have 8 month between them .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2016 07:21:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-ids-with-at-least-two-events-that-are-less-than-12-months/m-p/281353#M57042</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-06-30T07:21:32Z</dc:date>
    </item>
    <item>
      <title>Re: Find ids with at least two events that are less than 12 months apart</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-ids-with-at-least-two-events-that-are-less-than-12-months/m-p/281355#M57043</link>
      <description>&lt;P&gt;Your rule and your wanted result don't match.&lt;/P&gt;
&lt;P&gt;id 2 has less than 12 months between July 5, 2006 and March 3, 2007.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Jun 2016 07:23:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-ids-with-at-least-two-events-that-are-less-than-12-months/m-p/281355#M57043</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-06-30T07:23:59Z</dc:date>
    </item>
    <item>
      <title>Re: Find ids with at least two events that are less than 12 months apart</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-ids-with-at-least-two-events-that-are-less-than-12-months/m-p/281357#M57044</link>
      <description>&lt;P&gt;OK. Assuming I follow your logic .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id     event_Date : mmddyy10.;
format  event_Date  mmddyy10.;
cards;
1      1/1/2005
1      2/21/2007
1      2/22/2007
1     12/5/2004
2     1/1/2004
2     3/3/2006
2     7/5/2007
3    11/2/2004
3     1/5/2005
;
run;
proc sql;
create table want as
select * from have where id in (
 select distinct a.id 
  from have as a,have as b
   where a.id=b.id and a.event_Date ne b.event_Date and 
    abs(intck('month',a.event_Date,b.event_Date,'c')) le 12
);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Jun 2016 07:26:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-ids-with-at-least-two-events-that-are-less-than-12-months/m-p/281357#M57044</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-06-30T07:26:36Z</dc:date>
    </item>
    <item>
      <title>Re: Find ids with at least two events that are less than 12 months apart</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-ids-with-at-least-two-events-that-are-less-than-12-months/m-p/281358#M57045</link>
      <description>&lt;P&gt;If the aforementioned discrepancy was just a typo, this might be a solution:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id event_date :mmddyy10.;
format event_date mmddyy10.;
cards;
1 1/1/2005
1 2/21/2007
1 2/22/2007
1 12/5/2004
2 1/1/2004
2 3/3/2007
2 7/5/2005
3 11/2/2004
3 1/5/2005
;
run;

proc sort data=have;
by id event_date;
run;

data want (keep=id);
set have;
by id;
retain flag;
prev_date = lag(event_date);
if first.id then flag = 0;
else do;
  if intck('month',prev_date,event_date,'cont') &amp;lt;= 12 then flag = 1;
end;
if last.id and flag then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 30 Jun 2016 07:27:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-ids-with-at-least-two-events-that-are-less-than-12-months/m-p/281358#M57045</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-06-30T07:27:58Z</dc:date>
    </item>
    <item>
      <title>Re: Find ids with at least two events that are less than 12 months apart</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-ids-with-at-least-two-events-that-are-less-than-12-months/m-p/281490#M57099</link>
      <description>Thank you both worked!</description>
      <pubDate>Thu, 30 Jun 2016 16:04:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-ids-with-at-least-two-events-that-are-less-than-12-months/m-p/281490#M57099</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-06-30T16:04:25Z</dc:date>
    </item>
    <item>
      <title>Re: Find ids with at least two events that are less than 12 months apart</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-ids-with-at-least-two-events-that-are-less-than-12-months/m-p/281589#M57131</link>
      <description>&lt;P&gt;For the sake of safety and speed, I suggest you to use&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser﻿&lt;/a&gt;&amp;nbsp;'s code ,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if there are two same event_date for the same ID , My code wouldn't be right.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jul 2016 00:50:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-ids-with-at-least-two-events-that-are-less-than-12-months/m-p/281589#M57131</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-07-01T00:50:05Z</dc:date>
    </item>
  </channel>
</rss>

