<?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: Identify three or more occurrences within seven days by a unique ID in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Identify-three-or-more-occurrences-within-seven-days-by-a-unique/m-p/691793#M210622</link>
    <description>&lt;P&gt;What if the pattern for an IP address was like this? There are more than 7 days from 05/May/2020 to 15/May/2020, but both can be a part of a 'within 7 days' streak.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;110.640.35, 12345, 05/May/2020
110.640.35, 23456, 09/May/2020
110.640.35, 34567, 11/May/2020
110.640.35, 45678, 15/May/2020&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 15 Oct 2020 11:33:30 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2020-10-15T11:33:30Z</dc:date>
    <item>
      <title>Identify three or more occurrences within seven days by a unique ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-three-or-more-occurrences-within-seven-days-by-a-unique/m-p/691706#M210572</link>
      <description>&lt;P&gt;This might be a tough one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset showing the date an IP address accessed an Account:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;IP, Account, Date&lt;/P&gt;&lt;P&gt;108.950.45, 12345, 5/May/2020&lt;/P&gt;&lt;P&gt;108.950.45, 54321, 6/May/2020&lt;/P&gt;&lt;P&gt;108.950.45, 67890, 10/May/2020&lt;/P&gt;&lt;P&gt;108.950.45, 09876, 11/May/2020&lt;/P&gt;&lt;P&gt;108.950.45, 45879, 11/May/2020&lt;/P&gt;&lt;P&gt;108.950.45, 54686, 30/May/2020&lt;/P&gt;&lt;P&gt;220.540.40, 45879, 05/May/2020&lt;/P&gt;&lt;P&gt;220.540.40, 94532, 11/May/2020&lt;/P&gt;&lt;P&gt;220.540.40, 45879, 11/May/2020&lt;/P&gt;&lt;P&gt;110.640.35, 54873, 05/May/2020&lt;/P&gt;&lt;P&gt;110.640.35, 56454, 05/May/2020&lt;/P&gt;&lt;P&gt;110.640.35, 87654, 20/May/2020&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to create a dataset that shortlists any IP address that touched three or more&amp;nbsp;&lt;EM&gt;unique&lt;/EM&gt; accounts within a seven day period. My output from above dataset would hence read:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;108.950.45, 12345, 5/May/2020&lt;/P&gt;&lt;P&gt;108.950.45, 54321, 6/May/2020&lt;/P&gt;&lt;P&gt;108.950.45, 67890, 10/May/2020&lt;/P&gt;&lt;P&gt;108.950.45, 09876, 11/May/2020&lt;/P&gt;&lt;P&gt;108.950.45, 45879, 11/May/2020&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the above output there are three more accounts linked to same IP within a seven day window.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;220.540.40 would not be in final output as it interacted with two&amp;nbsp;&lt;EM&gt;unique&amp;nbsp;&lt;/EM&gt;Accounts.&amp;nbsp;110.640.35 would also not appear as it did not interact with three accounts in less than 7 days (it took 15 days).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions how to tackle this problem?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2020 00:10:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-three-or-more-occurrences-within-seven-days-by-a-unique/m-p/691706#M210572</guid>
      <dc:creator>wylie_ma</dc:creator>
      <dc:date>2020-10-15T00:10:37Z</dc:date>
    </item>
    <item>
      <title>Re: Identify three or more occurrences within seven days by a unique ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-three-or-more-occurrences-within-seven-days-by-a-unique/m-p/691716#M210576</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/341412"&gt;@wylie_ma&lt;/a&gt;&amp;nbsp; My apologies as I haven't tested as I'm awefully tired after a long day. The following should be close. If not, sure you should have the much needed solution&amp;nbsp;while&amp;nbsp;we folks at eastern time US are asleep. Nonetheless, Please try, test and let me know should you need any further.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
infile cards dsd ;
input IP :$30. Account $ Date	:date9.;
format date date9.;
cards;
108.950.45, 12345, 5/May/2020
108.950.45, 54321, 6/May/2020
108.950.45, 67890, 10/May/2020
108.950.45, 09876, 11/May/2020
108.950.45, 45879, 11/May/2020
108.950.45, 54686, 30/May/2020
220.540.40, 45879, 05/May/2020
220.540.40, 94532, 11/May/2020
220.540.40, 45879, 11/May/2020
110.640.35, 54873, 05/May/2020
110.640.35, 56454, 05/May/2020
110.640.35, 87654, 20/May/2020
;

data want;
 if _n_=1 then do;
   dcl hash H () ;
   h.definekey  ("account") ;
   h.definedata ("account","ip", "date") ;
   h.definedone () ;
   dcl hiter hi('h');
 end;
 do until(last.ip);
  set have;
  by ip notsorted;
  if date&amp;lt;=_n then if h.check() ne 0 then do;
   _c+1;
   h.add();
  end;
  if date&amp;gt;_n or last.ip  then do;
   	if _c&amp;gt;=3 then do while(hi.next()=0);
	 output;
	end;
	_c=1;
    _n=date+7;
	h.clear();
	h.add();
  end;
 end;
 drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="results.PNG" style="width: 437px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50680i7045B5162B6E1D79/image-size/large?v=v2&amp;amp;px=999" role="button" title="results.PNG" alt="results.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2020 02:37:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-three-or-more-occurrences-within-seven-days-by-a-unique/m-p/691716#M210576</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-10-15T02:37:26Z</dc:date>
    </item>
    <item>
      <title>Re: Identify three or more occurrences within seven days by a unique ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-three-or-more-occurrences-within-seven-days-by-a-unique/m-p/691725#M210581</link>
      <description>&lt;P&gt;Thanks so much again! I wish there was a button I could use on this page to tip you&lt;/P&gt;</description>
      <pubDate>Thu, 15 Oct 2020 02:52:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-three-or-more-occurrences-within-seven-days-by-a-unique/m-p/691725#M210581</guid>
      <dc:creator>wylie_ma</dc:creator>
      <dc:date>2020-10-15T02:52:44Z</dc:date>
    </item>
    <item>
      <title>Re: Identify three or more occurrences within seven days by a unique ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-three-or-more-occurrences-within-seven-days-by-a-unique/m-p/691793#M210622</link>
      <description>&lt;P&gt;What if the pattern for an IP address was like this? There are more than 7 days from 05/May/2020 to 15/May/2020, but both can be a part of a 'within 7 days' streak.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;110.640.35, 12345, 05/May/2020
110.640.35, 23456, 09/May/2020
110.640.35, 34567, 11/May/2020
110.640.35, 45678, 15/May/2020&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Oct 2020 11:33:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-three-or-more-occurrences-within-seven-days-by-a-unique/m-p/691793#M210622</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-10-15T11:33:30Z</dc:date>
    </item>
    <item>
      <title>Re: Identify three or more occurrences within seven days by a unique ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-three-or-more-occurrences-within-seven-days-by-a-unique/m-p/693028#M211253</link>
      <description>&lt;P&gt;Hypothetically, if I run add an additional row to dataset (see row 3 below), where IP address accesses the same account within 7 days, the code currently will only pickup the&amp;nbsp;&lt;EM&gt;first&lt;/EM&gt; entry within a seven day range.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;infile cards dsd ;&lt;BR /&gt;input IP :$30. Account $ Date :date9.;&lt;BR /&gt;format date date9.;&lt;BR /&gt;cards;&lt;BR /&gt;108.950.45, 12345, 5/May/2020&lt;BR /&gt;108.950.45, 54321, 6/May/2020&lt;BR /&gt;&lt;STRONG&gt;108.950.45, 54321, 13/May/2020&lt;/STRONG&gt;&lt;BR /&gt;108.950.45, 67890, 10/May/2020&lt;BR /&gt;108.950.45, 09876, 11/May/2020&lt;BR /&gt;108.950.45, 45879, 11/May/2020&lt;BR /&gt;108.950.45, 54686, 30/May/2020&lt;BR /&gt;220.540.40, 45879, 05/May/2020&lt;BR /&gt;220.540.40, 94532, 11/May/2020&lt;BR /&gt;220.540.40, 45879, 11/May/2020&lt;BR /&gt;110.640.35, 54873, 05/May/2020&lt;BR /&gt;110.640.35, 56454, 05/May/2020&lt;BR /&gt;110.640.35, 87654, 20/May/2020&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there anyway to adjust code so that it will pickup all entries within seven day range, even if it is the same account? See below for desired output. Also, if my date format is datetime20., will code be compatible with this format?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;108.950.45 54321 06MAY2020&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;108.950.45 45879 11MAY2020&lt;BR /&gt;108.950.45 67890 10MAY2020&lt;BR /&gt;108.950.45 12345 05MAY2020&lt;BR /&gt;108.950.45 09876 11MAY2020&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;108.950.45 54321&amp;nbsp;13MAY2020&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Oct 2020 23:56:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-three-or-more-occurrences-within-seven-days-by-a-unique/m-p/693028#M211253</guid>
      <dc:creator>wylie_ma</dc:creator>
      <dc:date>2020-10-20T23:56:50Z</dc:date>
    </item>
    <item>
      <title>Re: Identify three or more occurrences within seven days by a unique ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-three-or-more-occurrences-within-seven-days-by-a-unique/m-p/693169#M211325</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/341412"&gt;@wylie_ma&lt;/a&gt;&amp;nbsp; First off, a repeat occurrence of the same account within a particular interval &lt;STRONG&gt;changes&lt;/STRONG&gt; your original stated requirement/objective. However, sure it's possible. Also, if you have datetime values instead of date values, we could extract the date value from a datetime value using a datepart function.&amp;nbsp; It's not a big deal.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ideally, new requirement is better addressed as independent threads instead all in one. Anyways, Please review your requirement thoroughly and let me know as 13may2020 is outside of of the 1st seven interval i.e.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;interval 1: 5may2020- 12may2020&amp;nbsp; &amp;nbsp;(5+7)&lt;/P&gt;
&lt;P&gt;and the next goes like anything higher 12may2020 is found, increment the interval by +7 from that date.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 13:21:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-three-or-more-occurrences-within-seven-days-by-a-unique/m-p/693169#M211325</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-10-21T13:21:06Z</dc:date>
    </item>
    <item>
      <title>Re: Identify three or more occurrences within seven days by a unique ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-three-or-more-occurrences-within-seven-days-by-a-unique/m-p/693232#M211348</link>
      <description>&lt;P&gt;Thank you Novinisrin, Will do!&lt;/P&gt;</description>
      <pubDate>Wed, 21 Oct 2020 15:50:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-three-or-more-occurrences-within-seven-days-by-a-unique/m-p/693232#M211348</guid>
      <dc:creator>wylie_ma</dc:creator>
      <dc:date>2020-10-21T15:50:18Z</dc:date>
    </item>
    <item>
      <title>Re: Identify three or more occurrences within seven days by a unique ID</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Identify-three-or-more-occurrences-within-seven-days-by-a-unique/m-p/693790#M211578</link>
      <description>&lt;P&gt;A SQL query with a counting sub-select can create the desired result set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create index IP on have;

  create table want as 
  select *
  from have as each
  where 3 &amp;lt;= (
    select count(distinct lookup.account)
    from have as lookup
    where lookup.IP = each.IP
      and lookup.date between each.date-7 and each.date+7
    )    
  ;
quit;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Oct 2020 16:22:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Identify-three-or-more-occurrences-within-seven-days-by-a-unique/m-p/693790#M211578</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-10-23T16:22:44Z</dc:date>
    </item>
  </channel>
</rss>

