<?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 can I match two tables by nearest time? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-match-two-tables-by-nearest-time/m-p/104304#M21781</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi! I only had to make a minimum changes and it works. I'd forgotten that you can use &amp;gt; or &amp;lt; while matching. Thank you very much! &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 10 Oct 2013 19:55:10 GMT</pubDate>
    <dc:creator>fri0</dc:creator>
    <dc:date>2013-10-10T19:55:10Z</dc:date>
    <item>
      <title>How can I match two tables by nearest time?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-match-two-tables-by-nearest-time/m-p/104300#M21777</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, I have a problem trying to match to two tables by nearest time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've attached two samples of my tables. The idea is add the column PRICE from MATRIZELEX to MATRIZCB but with a specific condition.&lt;/P&gt;&lt;P&gt;I don't know if is necessary sort the tables, because the matching should avoid that problem.&lt;/P&gt;&lt;P&gt;Then, the condition is: For each row in MATRIZCB, I have to add the PRICE from MATRIZELEX where PRICE has to be the intermediately preceding by time and NEMONICO=TICKER, FECNEG=FECHA and HORNEG&amp;gt;TIME but TIME has to be the nearest time to HORNEG.&lt;/P&gt;&lt;P&gt;I'm sorry if my english is not good. I'll make an example of what I want:&lt;/P&gt;&lt;P&gt;One row in Table MATRIZCB could be:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ID FECNEG HORNEG NEMONICO PRECIO_ORDEN&lt;/P&gt;&lt;P&gt;1262834 24/09/13 12:32:39p.m. FERREYC1 1.83&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Looking the table MATRIZELEX for the same date (MATRIZELEX.DATE) and same Nemonico (MATRIZELEX.TICKER) we have 6 results:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;FECHA TIME TICKER PRICE&lt;/P&gt;&lt;P&gt;24/09/13 12:33:17p.m. FERREYC1 1.83&lt;/P&gt;&lt;P&gt;24/09/13 12:33:17p.m. FERREYC1 1.83&lt;/P&gt;&lt;P&gt;24/09/13 12:33:17p.m. FERREYC1 1.83&lt;/P&gt;&lt;P&gt;24/09/13 12:32:39p.m. FERREYC1 1.81&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;24/09/13 10:59:21a.m. FERREYC1 1.83&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;24/09/13 09:58:11a.m. FERREYC1 1.83&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, I only need the PRICE of the record that is lower and nearest with the record in MATRIZCB. As the record in MATRIZCB has the time 12:32:39pm, the matching register has to be record with time 10:59:21a.m. in MATRIZCB.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I tried to use PROC SQL making a join between the tables and getting the differences between times in order to select the minor value but I got multiple values by each row in MATRIZCB. Could you help me please? There is no difference for me if you use sql o data or whatever. Thanks in advance!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Oct 2013 20:42:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-match-two-tables-by-nearest-time/m-p/104300#M21777</guid>
      <dc:creator>fri0</dc:creator>
      <dc:date>2013-10-04T20:42:01Z</dc:date>
    </item>
    <item>
      <title>Re: How can I match two tables by nearest time?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-match-two-tables-by-nearest-time/m-p/104301#M21778</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How big will your datasets be in reality? There are many ways to do this...some more efficient than others.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Oct 2013 21:16:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-match-two-tables-by-nearest-time/m-p/104301#M21778</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-10-04T21:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: How can I match two tables by nearest time?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-match-two-tables-by-nearest-time/m-p/104302#M21779</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;About 30,000 rows&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Oct 2013 21:28:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-match-two-tables-by-nearest-time/m-p/104302#M21779</guid>
      <dc:creator>fri0</dc:creator>
      <dc:date>2013-10-04T21:28:07Z</dc:date>
    </item>
    <item>
      <title>Re: How can I match two tables by nearest time?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-match-two-tables-by-nearest-time/m-p/104303#M21780</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's one inefficient way, untested and a skeleton.&lt;/P&gt;&lt;P&gt;Basically, do the join and then use a data step to take only the first record which would be the earliest match? You may need the last instead, I haven't considered the problem thoroughly.&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 want1 as&lt;/P&gt;&lt;P&gt;select a.*, b.price&lt;/P&gt;&lt;P&gt;from table1 a&lt;/P&gt;&lt;P&gt;left join table2 b&lt;/P&gt;&lt;P&gt;on&lt;/P&gt;&lt;P&gt;NEMONICO=TICKER and&amp;nbsp; FECNEG=FECHA and HORNEG&amp;gt;TIME&lt;/P&gt;&lt;P&gt;order by NEMONICO, FECNEG , HORNEG;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set want1;&lt;/P&gt;&lt;P&gt;by NEMONICO FECNEG;&lt;/P&gt;&lt;P&gt;if first.FECNEG;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Oct 2013 22:33:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-match-two-tables-by-nearest-time/m-p/104303#M21780</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-10-04T22:33:42Z</dc:date>
    </item>
    <item>
      <title>Re: How can I match two tables by nearest time?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-can-I-match-two-tables-by-nearest-time/m-p/104304#M21781</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi! I only had to make a minimum changes and it works. I'd forgotten that you can use &amp;gt; or &amp;lt; while matching. Thank you very much! &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Oct 2013 19:55:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-can-I-match-two-tables-by-nearest-time/m-p/104304#M21781</guid>
      <dc:creator>fri0</dc:creator>
      <dc:date>2013-10-10T19:55:10Z</dc:date>
    </item>
  </channel>
</rss>

