<?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: How to locate a record in a time series that is 'x' minutes ahead in time? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136223#M36743</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Xia,&lt;/P&gt;&lt;P&gt;the task is to find the record which is 5min ahead in time or if there is no such record then the one which is closest to 5mins....&lt;/P&gt;&lt;P&gt;The code that Ballardw provided was simply an inner join which works only if the data have ALWAYS a matchning record....which is NOT the case so I need some kind of an sql search algorithm...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any ideas will help&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thnx&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Neo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 28 Jul 2014 08:56:25 GMT</pubDate>
    <dc:creator>machete</dc:creator>
    <dc:date>2014-07-28T08:56:25Z</dc:date>
    <item>
      <title>How to locate a record in a time series that is 'x' minutes ahead in time?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136218#M36738</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a financial time series dataset with a frequency of seconds.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To perform statistical analysis I need to search and locate for every record (row), the record which is 5minutes ahead of time.&lt;/P&gt;&lt;P&gt;Then i would like to retain from the record which is 5minutes ahead two observations, the columns bidprc and offerprc and add then next to the original record.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For example if we take from my attached data:&lt;/P&gt;&lt;P&gt;time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; currency&amp;nbsp; bidprc&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; offerprc&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; dt&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;bidprc5min&amp;nbsp; offerpc5mins&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;08:07:09&amp;nbsp;&amp;nbsp; dem/chf&amp;nbsp;&amp;nbsp; 0.86760&amp;nbsp; 0.86770&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 09JAN97:08:07:09&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;STRONG&gt;to be located&amp;nbsp; to be located&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would like to locate above the record which is in at 08:12:09 or if no such record exists the one which is closest to that time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is it possible to perform the above search without creating two datasets and e.g using proc sql which is efficient and quick?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any ideas on how to program the above are more than welcome&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Neo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Jul 2014 15:44:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136218#M36738</guid>
      <dc:creator>machete</dc:creator>
      <dc:date>2014-07-24T15:44:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to locate a record in a time series that is 'x' minutes ahead in time?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136219#M36739</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Does the data ALWAYS have a record at exactly +5 minutes (300 seconds)?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If so something like this may work&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table newdata as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select a.*, b.bidprc as bidprc5min, b.offerprc as offerprc5min&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from have as a left join have as b&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on a.time = (b.time -300);&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Jul 2014 15:59:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136219#M36739</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-07-24T15:59:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to locate a record in a time series that is 'x' minutes ahead in time?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136220#M36740</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ballardw,&lt;/P&gt;&lt;P&gt;I will check if the above works. However there isnt a record always at 300 seconds and I would like to make sure that there is always a record in the new tables, so it would be best if the code you proposed can locate the next closest record e.g in 301 seconds or more....&lt;/P&gt;&lt;P&gt;Is it possible to do this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thnx&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Neo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 24 Jul 2014 16:29:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136220#M36740</guid>
      <dc:creator>machete</dc:creator>
      <dc:date>2014-07-24T16:29:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to locate a record in a time series that is 'x' minutes ahead in time?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136221#M36741</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The code you provided generates additional records. The sample has 50000 but&amp;nbsp; the newdata has 68350...any ideas why is that?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;also if i run the code on my whole dataset (&amp;gt;1 million records) i get many empty ones, where values have not been located. is it possible to change the code as below so that i can get results for all my records?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;on a.time &amp;gt;= (b.time - 300)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;thanks again!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="html" __jive_macro_name="code" class="jive_text_macro jive_macro_code _jivemacro_uid_14062906705461174" jivemacro_uid="_14062906705461174"&gt;
&lt;P&gt;&lt;/P&gt;


&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Jul 2014 12:16:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136221#M36741</guid>
      <dc:creator>machete</dc:creator>
      <dc:date>2014-07-25T12:16:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to locate a record in a time series that is 'x' minutes ahead in time?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136222#M36742</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;if you want the next closed record ,why not fetch the next obs ? if your table has already been sorted by DT .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;proc import datafile='c:\temp\fixing sample.xls' out=have dbms=xls replace;run;

data want;
merge have have(firstobs=2&amp;nbsp; keep=bidprc offerprc rename=(bidprc=bidprc5min offerprc=offerprc5min));
label&amp;nbsp; bidprc5min=' '&amp;nbsp; offerprc5min=' ';
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Jul 2014 13:24:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136222#M36742</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-07-25T13:24:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to locate a record in a time series that is 'x' minutes ahead in time?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136223#M36743</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Xia,&lt;/P&gt;&lt;P&gt;the task is to find the record which is 5min ahead in time or if there is no such record then the one which is closest to 5mins....&lt;/P&gt;&lt;P&gt;The code that Ballardw provided was simply an inner join which works only if the data have ALWAYS a matchning record....which is NOT the case so I need some kind of an sql search algorithm...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any ideas will help&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thnx&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Neo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jul 2014 08:56:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136223#M36743</guid>
      <dc:creator>machete</dc:creator>
      <dc:date>2014-07-28T08:56:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to locate a record in a time series that is 'x' minutes ahead in time?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136224#M36744</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you assign each row to a grouping variable, for instance actual time vs planned timepoint.&lt;/P&gt;&lt;P&gt;HAVE&lt;/P&gt;&lt;P&gt;ACTUAL_TIME&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BASE_TIME&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GROUP_ASSIGNED&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GROUPN&lt;/P&gt;&lt;P&gt;12:34&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12:34&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BASELINE&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;12:36&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12:34&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BASELINE+5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;12:37&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12:34&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BASELINE+5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&lt;/P&gt;&lt;P&gt;12:43&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12:34&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BASELINE+10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3&lt;/P&gt;&lt;P&gt;12:47&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 12:34&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BASELINE+15&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 4&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can then group data into groups using the new variable irrespective of actual time, i.e;&lt;/P&gt;&lt;P&gt;select&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FIRST.ACTUAL_TIME,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NEXT.ACTUAL_TIME&lt;/P&gt;&lt;P&gt;from&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HAVE FIRST&lt;/P&gt;&lt;P&gt;left join&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HAVE NEXT&lt;/P&gt;&lt;P&gt;on&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FIRST.GROUPN=NEXT.GROUPN-1&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jul 2014 09:21:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136224#M36744</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-07-28T09:21:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to locate a record in a time series that is 'x' minutes ahead in time?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136225#M36745</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you change your logic?&lt;/P&gt;&lt;P&gt;It is a bit of strange thinking for future events that has happened already. It could be more easier thinking on calculations that have been happened in the paste.&lt;/P&gt;&lt;P&gt;That is more like stream processing. In that case the whole issue could be easier technical to solve (lag/retain) in am more generic way.&amp;nbsp;&amp;nbsp; &lt;BR /&gt;Validations on predictions (modeling) is a possible reason for your question.&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jul 2014 09:31:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136225#M36745</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2014-07-28T09:31:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to locate a record in a time series that is 'x' minutes ahead in time?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136226#M36746</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;H1 style="margin-bottom: .0001pt; background: white;"&gt;&lt;SPAN style="font-size: 10.0pt;"&gt;A trick used here: &lt;/SPAN&gt;&lt;SPAN style="color: #0e66ba; font-size: 10pt; font-family: inherit, serif;"&gt;&lt;A _jive_internal="true" href="https://communities.sas.com/message/217562#217562"&gt;Merging two datasets with different but similar columns&lt;/A&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; background-color: transparent;"&gt; helps here.&lt;/SPAN&gt;&lt;/H1&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt;"&gt;Dataset should be sorted by time.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt;"&gt;data have_minus5 / view&lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="font-size: 10.0pt;"&gt;=&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt;"&gt;have_minus5;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; time=time-'00:05:00't;/*or use intnx()*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rename &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Helvetica, sans-serif; background: white;"&gt;bidprc=&lt;SPAN style="font-family: 'Helvetica','sans-serif';"&gt;&lt;STRONG&gt;bidprc5min &lt;/STRONG&gt;&lt;/SPAN&gt;offerprc=&lt;SPAN style="font-family: 'Helvetica','sans-serif';"&gt;&lt;STRONG&gt;offerpc5mins;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.0pt;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt; background: white;"&gt;&lt;SPAN style="font-size: 10pt; font-family: Helvetica, sans-serif;"&gt;data want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background: white;"&gt;&lt;SPAN style="font-size: 10pt; font-family: Helvetica, sans-serif;"&gt;&amp;nbsp; set &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;have_minus5&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: Helvetica, sans-serif;"&gt;(in=inH5 keep=time) &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Helvetica, sans-serif;"&gt;have(in=inH keep=time)&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Helvetica, sans-serif;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background: white;"&gt;&lt;SPAN style="font-size: 10pt; font-family: Helvetica, sans-serif;"&gt;&amp;nbsp; by time;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background: white;"&gt;&lt;SPAN style="font-size: 10pt; font-family: Helvetica, sans-serif;"&gt;&amp;nbsp; if inH then do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background: white;"&gt;&lt;SPAN style="font-size: 10pt; font-family: Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background: white;"&gt;&lt;SPAN style="font-size: 10pt; font-family: Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background: white;"&gt;&lt;SPAN style="font-size: 10pt; font-family: Helvetica, sans-serif;"&gt;&amp;nbsp; end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background: white;"&gt;&lt;SPAN style="font-size: 10pt; font-family: Helvetica, sans-serif;"&gt;&amp;nbsp; if inH5 then do;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background: white;"&gt;&lt;SPAN style="font-size: 10pt; font-family: Helvetica, sans-serif;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt;"&gt;have_minus5&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Helvetica, sans-serif;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background: white;"&gt;&lt;SPAN style="font-size: 10pt; font-family: Helvetica, sans-serif;"&gt;&amp;nbsp; end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="background: white;"&gt;&lt;SPAN style="font-style: inherit; font-size: 10pt; font-family: inherit, serif; font-weight: inherit;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-US" style="font-size: 10.0pt;"&gt;&lt;SPAN style="text-decoration: line-through;"&gt;Sorry, this is not tested.&lt;/SPAN&gt; Tested. And yes, this is like stream processing.&amp;nbsp; ~ one pass through the data.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-US" style="font-size: 10.0pt;"&gt;&lt;SPAN lang="EN-US" style="font-size: 10pt; font-family: Arial, sans-serif;"&gt;Be careful when copying apostrophes from this page&lt;/SPAN&gt;, they are converted to something else.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;I have changed this set statement in the code: &lt;SPAN style="text-decoration: line-through;"&gt;&lt;SPAN style="font-size: 10pt; font-family: Helvetica, sans-serif;"&gt;set &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: Helvetica, sans-serif;"&gt;have(in=inH keep=time) &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;have_minus5&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em; font-family: Helvetica, sans-serif;"&gt;(in=inH5 keep=time);&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;It matters which dataset comes first. By changing dataset order in this set statement, you have a very fine control, over handling equal timestamps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Gergely Bathó&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jul 2014 11:38:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136226#M36746</guid>
      <dc:creator>gergely_batho</dc:creator>
      <dc:date>2014-07-28T11:38:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to locate a record in a time series that is 'x' minutes ahead in time?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136227#M36747</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is . But it cost me two minutes to run it. Let me know if it could worked.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;proc import datafile='c:\temp\fixing sample.xls' out=have dbms=xls replace;run;

proc sql;
create table want as
 select a.*,(select bidprc from have where time ge a.time+300 having time eq min(time) ) as bidprc5min
&amp;nbsp;&amp;nbsp; , (select offerprc from have where time ge a.time+300 having time eq min(time) ) as offerprc5min
&amp;nbsp; from have as a ;
quit;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 28 Jul 2014 14:18:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136227#M36747</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-07-28T14:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to locate a record in a time series that is 'x' minutes ahead in time?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136228#M36748</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;well I am nost sure how this will work as the orginal dataset will have 20million rows...re arranging the whole dataset into groups will be difficult...a search algorithm will work easier however I dont know how to program it....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Neo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Aug 2014 07:50:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136228#M36748</guid>
      <dc:creator>machete</dc:creator>
      <dc:date>2014-08-01T07:50:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to locate a record in a time series that is 'x' minutes ahead in time?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136229#M36749</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;i am doing both looking in the past but also tryng to 'validate' trading strategies...this is why I want to 'fetch' the records which are ahead (leading) in time fox x minutes&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Aug 2014 07:51:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136229#M36749</guid>
      <dc:creator>machete</dc:creator>
      <dc:date>2014-08-01T07:51:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to locate a record in a time series that is 'x' minutes ahead in time?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136230#M36750</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you can validate your strategies when processing those future records as the current one you do not need any reordering, it will be kept as stream-processing.&lt;/P&gt;&lt;P&gt;Just think in an other way to solve time questions. Suppose you have 100 strategies calculated. Evaluation can be done later (log/retain) not necessary at you current record. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Aug 2014 08:04:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136230#M36750</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2014-08-01T08:04:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to locate a record in a time series that is 'x' minutes ahead in time?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136231#M36751</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Neo, I realy suggest you to try the above mentioned approach. It runs very fast: 0.04 sec on the attached data. It needs only one pass through the data. 20mill rows will be not a problem.&lt;/P&gt;&lt;P&gt;With some more programming it can be extended to support different lookahead and lookback times. Or to support different currencies or more trading days.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Aug 2014 08:12:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136231#M36751</guid>
      <dc:creator>gergely_batho</dc:creator>
      <dc:date>2014-08-01T08:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to locate a record in a time series that is 'x' minutes ahead in time?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136232#M36752</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Gergely,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;by above you mean the one you proposed?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; I will run it and let you know, however by looking at the code I am almost sure that some records will be empty/unmatched since the records are not at regular intervals, it means there might be no record exactly at 5min ahead but 5minutes and 5 seconds and the code will need to check is there is no record to pick the next closest,in this case at 5mins and 5 seconds....I will let you know as soon as I check yours&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Neo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Aug 2014 14:10:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136232#M36752</guid>
      <dc:creator>machete</dc:creator>
      <dc:date>2014-08-01T14:10:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to locate a record in a time series that is 'x' minutes ahead in time?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136233#M36753</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Xia,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i tried your code but it does not work, any ideas why?? by reading it looks ok but it does not execute:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;15&amp;nbsp;&amp;nbsp; proc sql;&lt;/P&gt;&lt;P&gt;16&amp;nbsp;&amp;nbsp; create table fixing.fixing_eurchfsample1want as&lt;/P&gt;&lt;P&gt;17&amp;nbsp;&amp;nbsp; select a.*,(select bidprc from fixing.fixing_eurchfsample1 where time ge a.time+300 having&lt;/P&gt;&lt;P&gt;17 !&amp;nbsp; time eq min(time)) as bidprc5min,&lt;/P&gt;&lt;P&gt;18&amp;nbsp;&amp;nbsp; (select offerprc from fixing.fixing_eurchfsample1 where time ge a.time+300 having time eq&lt;/P&gt;&lt;P&gt;18 ! min(time))&amp;nbsp; as offerprc5min&lt;/P&gt;&lt;P&gt;19&amp;nbsp;&amp;nbsp; from fixing.fixing_eurchfsample1 as a ;&lt;/P&gt;&lt;P&gt;NOTE: The query requires remerging summary statistics back with the original data.&lt;/P&gt;&lt;P&gt;ERROR: Subquery evaluated to more than one row.&lt;/P&gt;&lt;P&gt;NOTE: Correlation values are: time=67400 .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;20&amp;nbsp;&amp;nbsp; quit;&lt;/P&gt;&lt;P&gt;NOTE: The SAS System stopped processing this step because of errors.&lt;/P&gt;&lt;P&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.45 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cpu time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.43 seconds&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Aug 2014 16:57:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136233#M36753</guid>
      <dc:creator>machete</dc:creator>
      <dc:date>2014-08-01T16:57:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to locate a record in a time series that is 'x' minutes ahead in time?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136234#M36754</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Finding the nearest match is always a bit tricky. I set up a time window to find the nearest match between t+120 and t+480 seconds.&lt;/P&gt;&lt;P&gt;The following works OK but is a bit slow. It might be a bit faster if &lt;STRONG&gt;dt&lt;/STRONG&gt; was indexed :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;libname xl Excel "&amp;amp;sasforum.\datasets\fixing sample.xls" access=readonly;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;create table s as&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;select input(dt, datetime20.) as dt format=datetime21., &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; bidprc, offerprc from xl.'Sheet1$'n;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;libname xl clear;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;create table want as &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;select &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.bidprc, a.offerprc, a.dt,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; b.bidprc as bidprc5, &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; b.offerprc as offerprc5, &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; b.dt as dt5,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; abs(intck('SECOND', a.dt, b.dt) - 300) as toff&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;from &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; s as a inner join &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; s as b&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; on b.dt between a.dt+120 and a.dt+480 &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;group by a.dt&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;having calculated toff = min(calculated toff); &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Aug 2014 18:47:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136234#M36754</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2014-08-01T18:47:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to locate a record in a time series that is 'x' minutes ahead in time?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136235#M36755</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The question as asked is not one for the SQL an not for analytics approaches.&lt;/P&gt;&lt;P&gt;Checking the sample dataset the timing with the events is very random at several second to minutes and longer.&lt;/P&gt;&lt;P&gt;As human you would put your finger on the line searching for the record you need an put new values in.&lt;BR /&gt;This a "balance line merge" algorithm known from 3 GL programming languages.&lt;/P&gt;&lt;P&gt;The dedicated problem is:&lt;/P&gt;&lt;P&gt;- merging the dataset to is self&amp;nbsp; &lt;/P&gt;&lt;P&gt;- assuming the data is sorted (dtcur) &lt;/P&gt;&lt;P&gt;The find condition is not very sophisticated the difference is 5 minutes except for the last records.&lt;/P&gt;&lt;P&gt;Once working this one could be improved. &lt;/P&gt;&lt;P&gt;Using the point option with the set statement moving using directs access in the dataset is possible.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Executing will be fast as long the cache on IO can solve all request (in memory).&lt;/P&gt;&lt;P&gt;Other techniques as sasfile or the hashobject are options with other limitations.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* create testdata ,&amp;nbsp; this is from excel using European conventions */&lt;/P&gt;&lt;P&gt;filename fixinp "/folders/myshortcuts/ikke" ; &lt;/P&gt;&lt;P&gt;data fixings ;&lt;BR /&gt; infile fixinp(fixingsample.csv) dlm=";" dsd firstobs=2 truncover ;&lt;BR /&gt; input date : mmddyy. time : time. currency : $8. bidprc : numx. offerprc : numx.&amp;nbsp; dtcur : datetime. ;&lt;BR /&gt; drop date time ;&lt;BR /&gt; eventid = _N_ ;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt; format dtcur datetime. ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* the set combine/merge using point wiht searching */&amp;nbsp; &lt;/P&gt;&lt;P&gt;data fixings300;&lt;BR /&gt;&amp;nbsp; set fixings nobs=fn_nobs ;&lt;BR /&gt;&amp;nbsp; Retain eventlk 1&amp;nbsp; ; check=1 ;&lt;BR /&gt;&amp;nbsp; do while (eventlk &amp;lt; fn_nobs &amp;amp; check ) ;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp; set fixings (rename=(bidprc=bidprc5 offerprc=offerprc5m eventid=event5m dtcur=dtcur5m) ) point=eventlk&amp;nbsp; end=end5m ;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp; if ( dtcur+300 &amp;gt; dtcur5m ) then eventlk=eventlk+1 ; else check=0;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;run;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Aug 2014 22:17:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136235#M36755</guid>
      <dc:creator>jakarman</dc:creator>
      <dc:date>2014-08-01T22:17:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to locate a record in a time series that is 'x' minutes ahead in time?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136236#M36756</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Much faster solution along the same lines as Jaap. The time window from 0 to 10 minutes is searched for the best match. If no observation occurs in that window, there is no match (missing values are generated)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;libname xl Excel "&amp;amp;sasforum.\datasets\fixing sample.xls" access=readonly;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;create table have as&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;select input(dt, datetime20.) as dt format=datetime21., &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; bidprc, offerprc from xl.'Sheet1$'n;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;libname xl clear;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;/* Number of seconds in the future to seek */&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%let matchGoal=300;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;/* Maximum number of seconds away from the goal to tolerate*/&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%let matchLimit=300;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data want;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;set have nobs=nobs;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;match = &amp;amp;matchLimit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;call missing(p5, dt5, bidprc5, offerprc5);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;do p = _n_+1 to nobs by 1 until (m &amp;gt; match);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have(keep=dt rename=dt=_dt) point=p;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; m = abs(intck('SECOND', dt, _dt) - &amp;amp;matchGoal);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if m &amp;lt; match then do;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; match = m;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; p5 = p;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;if not missing(p5) then do;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have(keep=dt bidprc offerprc &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rename=(dt=dt5 bidprc=bidprc5 offerprc=offerprc5))&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; point=p5;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;keep dt bidprc offerprc dt5 bidprc5 offerprc5;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 02 Aug 2014 03:14:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136236#M36756</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2014-08-02T03:14:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to locate a record in a time series that is 'x' minutes ahead in time?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136237#M36757</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is because there are duplicated rows for the same date and same time . E.X&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;01jan2010 00:08:21&amp;nbsp; 21&lt;/P&gt;&lt;P&gt;01jan2010 00:08:21&amp;nbsp; 54&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc import datafile='c:\temp\&lt;STRONG&gt;fixingsample&lt;/STRONG&gt;.xls' out=&lt;STRONG&gt;temp&lt;/STRONG&gt; dbms=xls replace;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc sort data=temp out=have nodupkey;by date time;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table want as&lt;/P&gt;&lt;P&gt;select a.*,(select bidprc from have where time ge a.time+300 having time eq min(time) ) as bidprc5min&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; , (select offerprc from have where time ge a.time+300 having time eq min(time) ) as offerprc5min&lt;/P&gt;&lt;P&gt;&amp;nbsp; from have as a ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 02 Aug 2014 06:38:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-locate-a-record-in-a-time-series-that-is-x-minutes-ahead/m-p/136237#M36757</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-08-02T06:38:37Z</dc:date>
    </item>
  </channel>
</rss>

