<?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 Working out time between two records by unique ID. in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Working-out-time-between-two-records-by-unique-ID/m-p/184925#M47012</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello there, could I please ask for some help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a table of records that has the Fields&amp;nbsp; "AccountID", "AuthDate", "AuthTime","Amount"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I'm trying to do is calculate how many unique ids have records where the AuthDate and Auth time are within 1 minute&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so for example if AccountID 1111 had two records on the 14/10/2014, one at 13:01:56 and one at 13:02:13 then this would be counted, obviously if there was then another on the same day at 13:02:31 then that would also be counted.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you in advance&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 Oct 2014 09:02:21 GMT</pubDate>
    <dc:creator>Stretlow</dc:creator>
    <dc:date>2014-10-15T09:02:21Z</dc:date>
    <item>
      <title>Working out time between two records by unique ID.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Working-out-time-between-two-records-by-unique-ID/m-p/184925#M47012</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello there, could I please ask for some help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a table of records that has the Fields&amp;nbsp; "AccountID", "AuthDate", "AuthTime","Amount"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I'm trying to do is calculate how many unique ids have records where the AuthDate and Auth time are within 1 minute&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;so for example if AccountID 1111 had two records on the 14/10/2014, one at 13:01:56 and one at 13:02:13 then this would be counted, obviously if there was then another on the same day at 13:02:31 then that would also be counted.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you in advance&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Oct 2014 09:02:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Working-out-time-between-two-records-by-unique-ID/m-p/184925#M47012</guid>
      <dc:creator>Stretlow</dc:creator>
      <dc:date>2014-10-15T09:02:21Z</dc:date>
    </item>
    <item>
      <title>Re: Working out time between two records by unique ID.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Working-out-time-between-two-records-by-unique-ID/m-p/184926#M47013</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You need to sort your dataset by AccountID AuthDate AuthTime.&lt;/P&gt;&lt;P&gt;Than with a data step you can process it: at each record you look back 1 record and look ahead 1 record and compare the times.&lt;/P&gt;&lt;P&gt;&lt;A href="http://www.sascommunity.org/wiki/Look-Ahead_and_Look-Back" title="http://www.sascommunity.org/wiki/Look-Ahead_and_Look-Back"&gt;Look-Ahead and Look-Back - sasCommunity&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Some more issues, you need to handle:&lt;/P&gt;&lt;P&gt;&amp;nbsp; combine date and time into date-time ( dhms() function)&lt;/P&gt;&lt;P&gt;&amp;nbsp; use inck() to calculate time difference, or simply substract date-times.&lt;/P&gt;&lt;P&gt;&amp;nbsp; be carefull at the beginning and at the end of an AccountID group&lt;/P&gt;&lt;P&gt;&amp;nbsp; flag (or delete or keep or count) the records (or the whole AccountID) that satisfy the condition.&lt;/P&gt;&lt;P&gt;useful thead:&lt;/P&gt;&lt;P&gt;&lt;A _jive_internal="true" class="active_link" href="https://communities.sas.com/message/217602#217602"&gt;https://communities.sas.com/message/217602#217602&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Post data and desired result if you need a more exact solution. Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Oct 2014 09:44:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Working-out-time-between-two-records-by-unique-ID/m-p/184926#M47013</guid>
      <dc:creator>gergely_batho</dc:creator>
      <dc:date>2014-10-15T09:44:50Z</dc:date>
    </item>
    <item>
      <title>Re: Working out time between two records by unique ID.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Working-out-time-between-two-records-by-unique-ID/m-p/184927#M47014</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It's often best to provide some sample data and then explain (show) how the desired result should look like.&lt;/P&gt;&lt;P&gt;Below some code creating such sample data and then an approach of how to get to what you want (or at least what I believe to understand that you want....).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; attrib &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; AccountID length=8&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; date format=date9.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; time format=time8.&lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; date=today();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do AccountID=1 to 10;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do _i=1 to 10;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; time=ceil(ranuni(1)*400)+60*60*10;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by AccountID date time;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by AccountID;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format DateTime _lag_DateTime datetime21.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; DateTime=sum(Date*86400,Time);&lt;/P&gt;&lt;P&gt;&amp;nbsp; _lag_DateTime=lag(DateTime);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if first.AccountID or DateTime-_lag_DateTime&amp;gt;60 then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ClusterID+1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 Oct 2014 11:40:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Working-out-time-between-two-records-by-unique-ID/m-p/184927#M47014</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2014-10-15T11:40:17Z</dc:date>
    </item>
  </channel>
</rss>

