<?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 perform a complex merge/matching procedure from two datasets in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95021#M26883</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you prefer a non-hash solution, a related question would be this.&amp;nbsp; Is the 64M data set sorted?&amp;nbsp; If so, in what order?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 10 Dec 2012 22:14:11 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2012-12-10T22:14:11Z</dc:date>
    <item>
      <title>How to perform a complex merge/matching procedure from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95013#M26875</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;SPAN style="color: #222222; font-size: 12pt; font-family: arial, helvetica, sans-serif;"&gt;Any support on this intellectual challenge is very much appreciated &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;SPAN style="color: #222222; font-size: 12pt; font-family: arial, helvetica, sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;SPAN style="color: #222222; font-size: 12pt; font-family: arial, helvetica, sans-serif;"&gt;The project:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;SPAN style="font-size: 12pt; font-family: arial, helvetica, sans-serif; color: #222222;"&gt;My project deals with high frequency (tick-by-tick) financial data&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;SPAN style="color: #222222; font-size: 12pt; font-family: arial, helvetica, sans-serif;"&gt;The task:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;SPAN style="font-size: 12pt; font-family: arial, helvetica, sans-serif; color: #222222;"&gt;I would like to merge and match two datasets. The first dataset has 2mln observations (financial transactions) and the second has 64mln observations. From the larger dataset I would like to match based on two specific variables (date and time). This means that at the end I will only add 2mln out of 64mln observations as a new variable to the first dataset.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;SPAN style="font-size: 12pt; font-family: arial, helvetica, sans-serif; color: #222222;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;SPAN style="font-size: 12pt; font-family: arial, helvetica, sans-serif; color: #222222;"&gt;The problem:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;SPAN style="font-size: 12pt; font-family: arial, helvetica, sans-serif; color: #222222;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;SPAN style="font-size: 12pt; color: #222222; font-family: arial, helvetica, sans-serif;"&gt;The problem I am facing is related to the fact that if no exact match between the “time” variable exists then I would like to take the next closest observation.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;SPAN style="font-size: 12pt; color: #222222; font-family: arial, helvetica, sans-serif;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;SPAN style="font-size: 12pt; color: #222222; font-family: arial, helvetica, sans-serif;"&gt;In more detail what Iwould like to do:&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif; font-size: 12pt;"&gt;&lt;SPAN style="color: black;"&gt;a- If variable A (currency code) in dataset A equals variable B (currency code) in dataset B, then check if date in dataset A equals date in dataset B, if correct, then check time in dataset A, if time in dataset A equals time in dataset B&lt;STRONG&gt; then&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN style="color: #222222;"&gt;(to avoid that there are variables which are not exactly matched because time is measured to the millisecond, if time in dataset A does not equal time in dataset B then take from dataset B the variable which is next closest in time of dataset A, that is t+1) &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-size: 12pt; font-family: arial, helvetica, sans-serif; color: #222222;"&gt;if in dataset A variable C (flow which takes values of 1 or 0) equals 1 then add in dataset A variable D from dataset B, else; add in Dataset A, variable E from Daraset B.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;SPAN style="font-size: 12pt; font-family: arial, helvetica, sans-serif; color: #222222;"&gt;b- Same process as above but this time instead of exact matching based on time, I would like to (match) take the variable that is +30 seconds further in time &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;SPAN style="font-size: 12pt; font-family: arial, helvetica, sans-serif; color: #222222;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;SPAN style="font-size: 12pt; font-family: arial, helvetica, sans-serif; color: #222222;"&gt;Hope you will be able to provide some feedback, I know this not an easy task, I have tried to tackle this issue with colleagues for a couple of weeks now.&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;SPAN style="font-size: 12pt; font-family: arial, helvetica, sans-serif; color: #222222;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;SPAN style="font-size: 12pt; font-family: arial, helvetica, sans-serif; color: #222222;"&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;SPAN style="font-size: 12pt; font-family: arial, helvetica, sans-serif; color: #222222;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;SPAN style="font-size: 12pt; font-family: arial, helvetica, sans-serif; color: #222222;"&gt;Neo&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Dec 2012 18:01:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95013#M26875</guid>
      <dc:creator>machete</dc:creator>
      <dc:date>2012-12-09T18:01:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a complex merge/matching procedure from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95014#M26876</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A small sample of those datasets would help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Dec 2012 22:11:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95014#M26876</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2012-12-09T22:11:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a complex merge/matching procedure from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95015#M26877</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And, in addition to samples of those datasets, it would help to know what kind of system you are on, which version of SAS you are running, and how big each of the two files really are (both in terms of numbers of records and filesize).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 09 Dec 2012 23:01:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95015#M26877</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-12-09T23:01:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a complex merge/matching procedure from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95016#M26878</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;We need some more rules...&lt;/P&gt;&lt;P&gt;Is it so that b.time always should be same or later (not before) a.time?&lt;/P&gt;&lt;P&gt;Do you have a performance constraint (that, should this job be executed multiple times, and within some kind of time frame)?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; This example code will probably have long execution time, be sure to have the appropriate indexes defined in both tables.&lt;/P&gt;&lt;P&gt;select a.*, (select time &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from b &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where a.currCd = b.currCd and &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.date = b.date and&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.time &amp;lt;= b.time&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; having b,time = max(b.time)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;/P&gt;&lt;P&gt;from&amp;nbsp; a&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Dec 2012 12:04:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95016#M26878</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2012-12-10T12:04:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a complex merge/matching procedure from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95017#M26879</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, &lt;A __default_attr="149594" __jive_macro_name="user" class="jive_macro jive_macro_user" data-objecttype="3" href="https://communities.sas.com/"&gt;&lt;/A&gt; and &lt;A __default_attr="2746" __jive_macro_name="user" class="jive_macro jive_macro_user" data-objecttype="3" href="https://communities.sas.com/"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Isn't this identical to the problem that you, Pierre, solved so brilliantly in &lt;A _jive_internal="true" href="https://communities.sas.com/message/146311#146311"&gt;https://communities.sas.com/message/146311#146311&lt;/A&gt; (What would be hash equivalent for this sql join?)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tom&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Dec 2012 19:15:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95017#M26879</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2012-12-10T19:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a complex merge/matching procedure from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95018#M26880</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A __default_attr="379045" __jive_macro_name="user" class="jive_macro jive_macro_user" data-objecttype="3" href="https://communities.sas.com/"&gt;&lt;/A&gt;: It sure sounds like it might be, but we won't know until the OP provides some more information.&amp;nbsp; I posted my response to the OP's question because, in the case of the question I had asked in the thread you mentioned, the actual solution that worked incorporated Pierre's brilliant approach within a somewhat complex design that used a combination of arrays and pointers.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Dec 2012 19:26:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95018#M26880</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-12-10T19:26:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a complex merge/matching procedure from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95019#M26881</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi to everybody,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your interest to my request &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I will try to respond to all of the above questions:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. I am using SAS 9.3&lt;/P&gt;&lt;P&gt;2. The dataset A has 2mln observations and a size of 23GB and dataset B 64mln observations and size 8GB (they are probably so large because I have no idea how to optimize them, i had dataset A running under another software and it was much smaller)&lt;/P&gt;&lt;P&gt;3. A bit more information on the problem. Dataset A contains 2 mln transactions of a brokerage company on the foreign exchange market during 90 days on an intraday frequency. That is, the transactions of Brokerage XYZ with different customers for 90 days for a specified number of currencies. Dataset B contains&amp;nbsp; 64mln transactions of fx transactions occured on the whole market between all conterparties during those same 90 days. What I would like to do is at a first step to identify for all broker trades(lets say the company i am studying), what is the difference between the price the brokerage transacted with a customer and the price which was prevailing on the market at that point of time. To make things clear assume the brokerage sold EUR/USD at a rate of 1.3150 on the 10.12.2012 at 09:30:45. I would like to look up the EUR/USD price in dataset B on the 10.12.2012 at 09:30:45. If there is no price available at 09:30:45 then the closest available which might be lets say 09:30:50. I would like then to merge the two sets as next to the market price in dataset B there are some more useful variables that I would like to add to the first dataset.&lt;/P&gt;&lt;P&gt;To perform the above I need to match the trades from dataset A to the trades from dataset B at exact times and if no exact match is possible the closest one. At a second stage I would like to match at a specific point in time, e.g time at dataset A+1min, then A+30mins and so forth.(the idea here is to study how the difference between the two prices (market and brokerage price) changes over time)&lt;/P&gt;&lt;P&gt;4. I will need to check whether I can upload any sample of the data as I have signed a confidentiality agreement related to my phd research and the data provider I know it is difficult to fully understand the problem without seeing the data so i will check to see if I can show the basic structure/content here.&lt;/P&gt;&lt;P&gt;5. Somebod mentioned the execution time of a proposed command. I am not looking for an efficient solution so time here will not be an issue, I simply need to solve this programming challenge. Since I am new with SAS and have no advanced skills, working with the mentioned dataset takes me around 15-20mins per command to be executed so I am used to it &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt; &lt;/P&gt;&lt;P&gt;6.One more thing. Here is the date structure from the two sets, any idea how to eqalize the date formats?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: #222222;"&gt;Dataset A - date variable(dd/mm/yyyy):&amp;nbsp;&amp;nbsp; “05/01/2012”&amp;nbsp; and time variable (hh:mm:ss):&amp;nbsp; “08:45:24”&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: #222222;"&gt;Dataset B - date variable&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: #222222;"&gt;: “21MAR12&lt;SPAN style="color: #222222; font-family: 'Courier New'; background-color: #ffffff;"&gt;”, &lt;SPAN style="color: #222222; font-family: 'Courier New'; background-color: #ffffff;"&gt;time variable:&lt;/SPAN&gt; &lt;SPAN style="color: #222222; font-family: 'Courier New'; background-color: #ffffff;"&gt;“08:45:24”&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;Thnx&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt; background-color: white; background-position: initial initial; background-repeat: initial initial;"&gt;Neo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Dec 2012 20:49:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95019#M26881</guid>
      <dc:creator>machete</dc:creator>
      <dc:date>2012-12-10T20:49:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a complex merge/matching procedure from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95020#M26882</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If your tables both are Base SAS, and your data and time columns are numeric - don't concern about formats. They are just for display, and different formats doesn't affect join criteria etc.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;About the +1 and +30 logic. Just rerun the original query, but with difference that you add 60 (it's number of seconds) to a.time, and then 1800 (no seconds for 30 minutes).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I guess that an hash table will solve this, but I wouldn't recommend that technique for a not so experienced SAS programmer.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Dec 2012 22:00:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95020#M26882</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2012-12-10T22:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a complex merge/matching procedure from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95021#M26883</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you prefer a non-hash solution, a related question would be this.&amp;nbsp; Is the 64M data set sorted?&amp;nbsp; If so, in what order?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Dec 2012 22:14:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95021#M26883</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2012-12-10T22:14:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a complex merge/matching procedure from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95022#M26884</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;When you say 64 min are you saying 64 million?&amp;nbsp; SAS will run fastest if the two files only contain the minimal amount of information necessary to accomplish the required task.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Given the background details you have provided the real data isn't necessary.&amp;nbsp; For people here to help, just create two sample datasets, with about 2 records in the one and about 20 records in the other (with both only containing the minimum number of variables needed to produce the desired result), as well as the file you want resulting from the program you are asking for help in creating.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Were the date and time fields input as text or as SAS dates and SAS times? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;From your description, I think you will want/need a solution much like the one we talked about in the thread that Tom mentioned.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 10 Dec 2012 22:34:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95022#M26884</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-12-10T22:34:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a complex merge/matching procedure from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95023#M26885</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;OL style="list-style-type: decimal;"&gt;&lt;LI&gt;I am not sure I get the difference between a hush and a non hush solution as well as to what is a base SAS table&lt;/LI&gt;&lt;LI&gt;The large dataset has 64million observations. They are sorted based on currency pair. That is I have all the records of the AUD/USD for 90 days, then follows CHF/USD for 90 days and so forth….&lt;/LI&gt;&lt;LI&gt;I uploaded a sample of the brokerage dataset (in our discussion dataset A) containing only the trades of 20&lt;SUP&gt;th&lt;/SUP&gt; of April and only concerning one currency pair, EUR/CHF.&amp;nbsp; If you have any questions they are welcome. Basic var description which are included: deal id, date, time, spot rate, amount/volume, flow (buy or sell). I have dropped at least 10 variables which are not important for the question we are currently discussing.&lt;/LI&gt;&lt;LI&gt;I can upload a similar sample with date and currency data from the “market” dataset B. However I have a problem filtering the data because I have the following date format:&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;'20APR12 00:00:00' and I need first to create a date variable containing the first 7 characters. I tried with the “substr” function but it delivers a number as a result and not “20APR12”. If you have any suggestions here I would be grateful, then I will upload a sample of this dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; 5. All date and time formats I had in csv or MS access format before uploading to SAS. I believe these were text formats&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; 6. Tomorrow also to follow the sample result sheet that A.Tabachneck mentioned&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Dec 2012 22:14:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95023#M26885</guid>
      <dc:creator>machete</dc:creator>
      <dc:date>2012-12-13T22:14:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a complex merge/matching procedure from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95024#M26886</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It is difficult to recommend a solution without seeing the other file and knowing more about the file you provided.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As for the data being a SAS table, your example and explanation indicate that both files are now SAS files.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hash (not hush) is a method that may or may not be applicable.&amp;nbsp; At this point, I can't say, but doubt it given the number of records that you have.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the file you've already provided, all of the dates and times were imported as 255 character variables.&amp;nbsp; My guess is that the ultimate recommendation will be to combine the two fields as a SAS datetime field.&amp;nbsp; That way, you can apply a format that will display them as desired, but still allow a program to access them as one field.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It will definitely help to understand more about the example file you already provided, as well as see an example of the other file.&amp;nbsp; Don't worry about the ultimate format for now.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Dec 2012 23:31:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95024#M26886</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-12-13T23:31:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a complex merge/matching procedure from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95025#M26887</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The best way to elaborate your question is to post a smaill sample data(as simple as it could be) and the &lt;STRONG&gt;result&lt;/STRONG&gt;&amp;nbsp; you want to see and at the same time explain the logic you have .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Dec 2012 02:08:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95025#M26887</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-12-14T02:08:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a complex merge/matching procedure from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95026#M26888</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;I will try to answer to the questions from above&lt;/P&gt;&lt;P&gt;I uploaded also a sample of the second dataset as well as an excel sheet showing an “example”output of how I would like the data to look after the merge has been implemented.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below a description of the datasets&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;STRONG&gt;DATASET A&lt;/STRONG&gt; &lt;STRONG&gt;:&lt;/STRONG&gt; Contains our brokers' trades with customers&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="margin-left: 4.65pt; width: 530px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding: 0 5.4pt 0 5.4pt;" valign="bottom" width="530"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;Deal_Id – a unique deal identifier, i.e the number of each trade&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding: 0 5.4pt 0 5.4pt;" valign="bottom" width="530"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;Cur1Cur2 – the currency pair&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding: 0 5.4pt 0 5.4pt;" valign="bottom" width="530"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;Amount1Cur1 – the volume of each trade&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding: 0 5.4pt 0 5.4pt;" valign="bottom" width="530"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;Spot_Rate – the price/exchange rate at which the deal is executed&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding: 0 5.4pt 0 5.4pt;" valign="bottom" width="530"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;Value_Date – the date when the deal is executed&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding: 0 5.4pt 0 5.4pt;" valign="bottom" width="530"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;Cpty – the customer with which our broker trades&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding: 0 5.4pt 0 5.4pt;" valign="bottom" width="530"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;Flow – it takes values of 1 and -1 if the broker is buying or selling respectively&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding: 0 5.4pt 0 5.4pt;" valign="bottom" width="530"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;Newtime – the time of day when the trade was executed in hh:mm:ss structure&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;RELEVANT DATA for our problem are only value date,cur1cur2, and newtime&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;&lt;STRONG&gt;DATASET B:&lt;/STRONG&gt; Contains all the trades executed on the market – That is it provides information on the prices executed on the whole market, i.e prices offered by other brokers&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding: 0 5.4pt 0 5.4pt;" valign="bottom" width="530"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;_RIC – the currency pair&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding: 0 5.4pt 0 5.4pt;" valign="bottom" width="530"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;Date_G_&amp;nbsp;&amp;nbsp; - the date of the trade&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding: 0 5.4pt 0 5.4pt;" valign="bottom" width="530"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;Time_G_ - the time of day of the trade&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding: 0 5.4pt 0 5.4pt;" valign="bottom" width="530"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;GMT_Offset - not relevant&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding: 0 5.4pt 0 5.4pt;" valign="bottom" width="530"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;Type - not relevant&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding: 0 5.4pt 0 5.4pt;" valign="bottom" width="530"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;Ex_Cntrb_ID - who is trading (here I extracted prices by only one broker to minimize the size of the dataset)&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding: 0 5.4pt 0 5.4pt;" valign="bottom" width="530"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;LOC – not relevant&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding: 0 5.4pt 0 5.4pt;" valign="bottom" width="530"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;Price – not relevant&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding: 0 5.4pt 0 5.4pt;" valign="bottom" width="530"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;Volume – not relevant&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding: 0 5.4pt 0 5.4pt;" valign="bottom" width="530"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;Market_VWAP – not relevant&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding: 0 5.4pt 0 5.4pt;" valign="bottom" width="530"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;Bid_Price Price offered for the trade (if customer wants to buy)&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding: 0 5.4pt 0 5.4pt;" valign="bottom" width="530"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;Bid_Size – not relevant&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding: 0 5.4pt 0 5.4pt;" valign="bottom" width="530"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;Ask_Price Price asked for the trade (if customer wants to sell)&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding: 0 5.4pt 0 5.4pt;" valign="bottom" width="530"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;Ask_Size – not relevant&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding: 0 5.4pt 0 5.4pt;" valign="bottom" width="530"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;Qualifiers – not relevant&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding: 0 5.4pt 0 5.4pt;" valign="bottom" width="530"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;Bid_Yld – not relevant&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding: 0 5.4pt 0 5.4pt;" valign="bottom" width="530"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;Ask_Yld – not relevant&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding: 0 5.4pt 0 5.4pt;" valign="bottom" width="530"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;Ric_2 – not relevant&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding: 0 5.4pt 0 5.4pt;" valign="bottom" width="530"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;_ric2 – the currency pair in comparable format to DATASET A&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD nowrap="nowrap" style="padding: 0 5.4pt 0 5.4pt;" valign="bottom" width="530"&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black;"&gt;Midquote – the difference of the bid with the ask price divided by 2&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;DATA RELEVANT: for our problem relevant are _ric2 has to be the same as cur1cur2, then date_G_ has to be the same as value date and then newtime has to be the same as time_g_. then as a result of add to each the corresponding information of dataset b next to dataset a.In case newtime is not the same as time_g_ please match with the next closest observation of time_g_.&lt;/P&gt;&lt;P&gt;I think this should make things a bit more clear of what i am trying to do in this exercise at a first stage.&lt;/P&gt;&lt;P&gt;THE FINAL OUTPUT EXAMPLE (attached excel sheet): Have in mind that this example shows only the case where no exact match by time will be possible and the next closest value will be taken.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks and a fruitful week to everybody&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Neo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 16 Dec 2012 22:47:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95026#M26888</guid>
      <dc:creator>machete</dc:creator>
      <dc:date>2012-12-16T22:47:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a complex merge/matching procedure from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95027#M26889</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think it is easy for Hash Table.&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;PRE&gt;libname x v9 'd:\software';
data&amp;nbsp; c2;
 set x.Chfdaily2;
 datetime=input(catx(':',value_date,newtime),anydtdtm20.);
format datetime datetime.;
run;
data c3;
 set x.Chfreuters3;
 datetime=dhms(datepart(Date_G_),0,0,int(Time_G_));
 format datetime datetime.;
run;
data want;
 if _n_ eq 1 then do;
 if 0 then set c3;
&amp;nbsp; declare hash ha(hashexp:16,dataset:'c3');
&amp;nbsp;&amp;nbsp; ha.definekey('_ric2','datetime');
&amp;nbsp;&amp;nbsp; ha.definedata(all:'Y');
&amp;nbsp;&amp;nbsp; ha.definedone();
 end;
call missing(of _all_);
set c2;
_ric2 =cur1cur2;
datepart=datepart(datetime);
do while(ha.find() ne 0);
 datetime+1;
 if datepart ne datepart(datetime) then leave;
end;
drop datepart;
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;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Dec 2012 05:21:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95027#M26889</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-12-17T05:21:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a complex merge/matching procedure from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95028#M26890</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ksharp, It works &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt; Thank you so much &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt; Below I have a small set of questions that are related on how to improve the code you provided and how to do a similar merge. Hope you will be able to support me on this. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;OL style="list-style-type: decimal;"&gt;&lt;LI&gt;I would like to make a similar merge of the datasets as the one described before. This time instead of exact time matching, I would like to “locate” the value in dataset “Chfreuters3” which is 60 seconds or e.g 1800 seconds &lt;SPAN style="text-decoration: underline;"&gt;after&lt;/SPAN&gt; datetime in Chfdaily2. Any suggestions on how I should change the code you provided? Also I would like to do the opposite, locate the value which is 60 seconds before datetime in Chfdaily2. The difference from the exercise from before is that in the output table I would like to add only a specified number of variables, e.g datetime and midquote and not all from chfreuters3.&lt;/LI&gt;&lt;LI&gt;Going back to the code you provided: How datetime can be included in the final output table for dataset Chfreuters3, since datetime of dataset Chfdaily2 might be different of datetime of dataset Chfreuters3 in the output table. This is the case when we do not have an exact time match from the two sets and I would like to retain both new dateformats. &lt;/LI&gt;&lt;LI&gt;Can you have a look at the result I uploaded under filename want? Why do you think row 5 gives such a result? &lt;/LI&gt;&lt;LI&gt;For info here is the code I used – I only updated yours by using different datasets and library locations&lt;/LI&gt;&lt;/OL&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;libname&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; neo v9 &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'d:\phd thesis\sas files'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp; neo.c2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; neo.Chfdaily2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; datetime=input(catx(&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;':'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;,value_date,newtime),&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: teal; background: white;"&gt;anydtdtm20.&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;format&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; datetime &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: teal; background: white;"&gt;datetime.&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; neo.c3;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; neo.Chfr;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; datetime=dhms(datepart(Date_G_),&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;,&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;,int(Time_G_));&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;format&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; datetime &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: teal; background: white;"&gt;datetime.&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; neo.want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; _n_ eq &lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;then&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;do&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;if&lt;/SPAN&gt; &lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;then&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; c3;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;declare&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; hash ha(hashexp:&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;16&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;,dataset:&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'c3'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp; ha.definekey(&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'_ric2'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'datetime'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp; ha.definedata(all:&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;'Y'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp; ha.definedone();&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;call&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; missing(of _all_);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; c2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;_ric2 =cur1cur2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;datepart=datepart(datetime);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;do&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;while&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;(ha.find() ne &lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; datetime+&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; datepart ne datepart(datetime) &lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;then&lt;/SPAN&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;leave&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;drop&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; datepart LOC Price Volume;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 17 Dec 2012 21:40:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95028#M26890</guid>
      <dc:creator>machete</dc:creator>
      <dc:date>2012-12-17T21:40:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a complex merge/matching procedure from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95029#M26891</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK. Let's look at it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"I would like to “locate” the value in dataset “Chfreuters3” which is 60 seconds or e.g 1800 seconds &lt;SPAN style="text-decoration: underline;"&gt;after&lt;/SPAN&gt; datetime in Chfdaily2.&lt;/P&gt;&lt;P&gt;I would like to add only a specified number of variables, e.g datetime and midquote and not all from chfreuters3"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That would be more simple than one before. See the code below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"How datetime can be included in the final output table for dataset Chfreuters3, since datetime of dataset Chfdaily2 might be different of datetime of dataset Chfreuters3 in the output table."&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Actually the datetime doesn't matter. I use datetime to locate the recode in Chfreuters3. The value of datetime will change during the data step. You can ignore it, just see the value_date,newtime&amp;nbsp; in Chfdaily2 .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"Can you have a look at the result I uploaded under filename want? Why do you think row 5 gives such a result?"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can find all the value of variables from Chfreuters3 are missing. That usually means we can't find a matched record from Chfreuters3. variable datetime will dynamically change during data step, therefore its value is not actually display its original value. You can ignore it , just see value_date,newtime&amp;nbsp; in Chfdaily2 or Date_G_,Time_G_ in Chfreuters3 to identify the record .&lt;/P&gt;&lt;P&gt;For row 5:&lt;/P&gt;&lt;P&gt;datetime&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; value_date&amp;nbsp; newtime&lt;/P&gt;&lt;P&gt;21APR12:00:00:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20/04/2012&amp;nbsp;&amp;nbsp;&amp;nbsp; 22:02:19&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We will start to locate the record from newtime=22:02:19&amp;nbsp; , and will find next newtime=22:02:20 and next and next again , until it cross the line of next day(datetime=21APR12:00:00:00 ).&amp;nbsp; You demand locating the record in the same day, therefore we stop locating when it reach the tomorrow.&lt;/P&gt;&lt;P&gt;Was it more clear ?&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;libname x v9 'd:\software';
data&amp;nbsp; c2;
 set x.Chfdaily2;
 datetime=input(catx(':',value_date,newtime),anydtdtm20.);
format datetime datetime.;
run;
data c3;
 set x.Chfreuters3;
 datetime=dhms(datepart(Date_G_),0,0,int(Time_G_));
 format datetime datetime.;
run;
data want;
 if _n_ eq 1 then do;
 if 0 then set c3(keep=_ric2 datetime midquote);
&amp;nbsp; declare hash ha(hashexp:16,dataset:'c3');
&amp;nbsp;&amp;nbsp; ha.definekey('_ric2','datetime');
&amp;nbsp;&amp;nbsp; ha.definedata('datetime','midquote');/*add the variables you need to merge in*/
&amp;nbsp;&amp;nbsp; ha.definedone();
 end;
call missing(of _all_);
set c2;
_ric2 =cur1cur2;
/*locate the value which is 60 seconds after datetime in Chfdaily2.
&amp;nbsp; if you want before ,change it to -60*/
datetime=datetime+60;
rc=ha.find();
drop rc _ric2;
run;
 

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: xia keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 18 Dec 2012 02:42:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95029#M26891</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-12-18T02:42:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a complex merge/matching procedure from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95030#M26892</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hi Ksharp,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;We are on the right way, I have however some more comments/questions:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. I apologize, I did not explain explicitly what I wanted to do. I would like to do the same as the first matching we did this time having +60 seconds of newtime as the basis. That is locate the value in time_g_ which is +60sec and if there is no exact match to take the next closest to +60 seconds(e.g +60sec+1?). I tried to adjust the code as below but it did not work…any idea where the mistake might lie? I think the change should be added somewhere in this part:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Times New Roman,serif; font-size: 12pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-family: Courier New,monospace;"&gt;set&lt;SPAN style="color: #000000;"&gt; c2;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New,monospace;"&gt;_ric2 =cur1cur2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New,monospace;"&gt;datepart=datepart(&lt;SPAN style="text-decoration: underline;"&gt;datetime+60&lt;/SPAN&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-family: Courier New,monospace;"&gt;do&lt;SPAN style="color: #575757;"&gt; &lt;/SPAN&gt;while&lt;SPAN style="color: #000000;"&gt;(ha.find() ne&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #008080;"&gt;&lt;STRONG&gt;0&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;);&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Courier New,monospace;"&gt;datetime+&lt;SPAN style="color: #008080;"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-family: Courier New,monospace;"&gt;if&lt;SPAN style="color: #000000;"&gt; datepart ne datepart(datetime&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;+60&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;) &lt;/SPAN&gt;then&lt;SPAN style="color: #575757;"&gt; &lt;/SPAN&gt;leave&lt;SPAN style="color: #000000;"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-family: Courier New,monospace;"&gt;end&lt;SPAN style="color: #000000;"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #0000ff; font-family: Courier New,monospace;"&gt;drop&lt;SPAN style="color: #000000;"&gt; datepart LOC Price Volume;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000080; font-family: Courier New,monospace;"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Times New Roman,serif; font-size: 12pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Times New Roman,serif; font-size: 12pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. you wrote 'You can find all the value of variables from Chfreuters3 are missing. That usually means we can't find a matched record from Chfreuters3. variable datetime will dynamically change during data step, therefore its value is not actually display its original value. You can ignore it , just see value_date,newtime&amp;nbsp; in Chfdaily2 or Date_G_,Time_G_ in Chfreuters3 to identify the record .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For row 5:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;datetime&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; value_date&amp;nbsp; newtime&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;21APR12:00:00:00&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20/04/2012&amp;nbsp;&amp;nbsp;&amp;nbsp; 22:02:19&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;We will start to locate the record from newtime=22:02:19&amp;nbsp; , and will find next newtime=22:02:20 and next and next again , until it cross the line of next day(datetime=21APR12:00:00:00 ).&amp;nbsp; You demand locating the record in the same day, therefore we stop locating when it reach the tomorrow.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Was it more clear ?'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Times New Roman,serif; font-size: 12pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Neo - However there is value that can be matched at time_g_ 22:02:45 in chfreuters3 but it is not matched, since the row/record is empty in our output table. why it is so?&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;3. I also wanted to ask whether this hash table solution will have any drawbacks in my further analysis. Will it create any limitations:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;a. When I run this command for matching in the total datasets which are 2mln and 64mln observations (in our examples we dealt only with one currency and one day, my original dataset has 10 currencies and 80 days)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;b. When I use the final table and start running my regressions/analysis&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am simply asking in order to have an idea in advance if I need to change smth to avoid such issues&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Times New Roman,serif; font-size: 12pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Calibri,sans-serif; font-size: 10pt;"&gt;Thanks and merry christmas to everybody &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Calibri,sans-serif; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Calibri,sans-serif; font-size: 10pt;"&gt;Neo&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 22 Dec 2012 12:28:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95030#M26892</guid>
      <dc:creator>machete</dc:creator>
      <dc:date>2012-12-22T12:28:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a complex merge/matching procedure from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95031#M26893</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your example datasets and desired output don't match.&amp;nbsp; One data set has records from January 2012, while the other only has records from April 2012.&amp;nbsp; And, since you refer to variables (sometimes) as Variable A, B, etc., rather than the actual variable names, there is room for confusion as to what you really want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;However, that said, your example big dataset doesn't have entries at specific intervals.&amp;nbsp; A large number have records that are 59 seconds after the previous records, an equally large number have records that are 61 seconds after the previous record, and a small number have larger gaps between the times shown in the records.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You never said (or at least I can't find your response) whether you simply want to match the closest record, regardless of whether it comes before or after the record being matched, or if you are ONLY interest in the exact match or time that comes closest AFTER the datetime of the record from the smaller dataset.&amp;nbsp; To the contrary, I'm seeing what appear to be confusing directions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Please restate your question using the variable names that actually exist in the datasets and indicate what the real rules are.&amp;nbsp; I think, trying to provide an explanation, you may have confused many of us.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is the larger dataset already in a sorted order and, if so, in what order?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 22 Dec 2012 18:23:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95031#M26893</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-12-22T18:23:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to perform a complex merge/matching procedure from two datasets</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95032#M26894</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Oh, That is easy.&lt;/P&gt;&lt;P&gt;You just need to turn &lt;SPAN style="font-family: Courier New,monospace;"&gt;datetime+&lt;SPAN style="color: #008080;"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;;&lt;/SPAN&gt; into &lt;SPAN style="font-family: Courier New,monospace;"&gt;datetime+&lt;SPAN style="color: #008080;"&gt;&lt;STRONG&gt;60&lt;/STRONG&gt;&lt;/SPAN&gt;;&lt;/SPAN&gt;. That is all. You don't need to change datepart which I used to justice whether it cross the line of tomorrow.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"Neo - However there is value that can be matched at time_g_ 22:02:45 in chfreuters3 but it is not matched"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I doubted that &lt;SPAN style="font-family: Courier New,monospace;"&gt;_ric2 not equal cur1cur2&lt;/SPAN&gt; . Check it more.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"3. I also wanted to ask whether this hash table solution will have any drawbacks in my further analysis. Will it create any limitations:"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The only limitation is computer memory.&amp;nbsp; your dataset is too large to execute Hash Table.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"I am simply asking in order to have an idea in advance if I need to change smth to avoid such issues"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you elaborate it more ?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Dec 2012 02:09:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-perform-a-complex-merge-matching-procedure-from-two/m-p/95032#M26894</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-12-24T02:09:50Z</dc:date>
    </item>
  </channel>
</rss>

