<?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: Matching a record based on Date in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Matching-a-record-based-on-Date/m-p/90659#M25890</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data h1;&lt;/P&gt;&lt;P&gt;input (AccountNo UniqueProductID) (:$10.) SaleDate ddmmyy10. SaleID:$10.;&lt;/P&gt;&lt;P&gt;format SaleDate ddmmyy10. ;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;3000 1612000 15/02/2011 ABXD1&lt;/P&gt;&lt;P&gt;3000 1612000 05/05/2011 AIIIU2&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data h2;&lt;/P&gt;&lt;P&gt;input (AccountNo UniqueProductID) (:$10.) usageDate ddmmyy10.;&lt;/P&gt;&lt;P&gt;format usageDate ddmmyy10.;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;100 1612000 20/02/2011&lt;/P&gt;&lt;P&gt;3000 1612000 03/06/2011&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*if your real data lays just as what you have shown: sorted, 1:1 ratio within the same accountno, then:*/&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;merge h1 h2;&lt;/P&gt;&lt;P&gt;by uniqueproductid;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*otherwise, not as efficient, but the following should work*/&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.accountno, a.UniqueProductID, saledate, usagedate, saleid from&lt;/P&gt;&lt;P&gt;h2 a&lt;/P&gt;&lt;P&gt;left join h1 b&lt;/P&gt;&lt;P&gt;on a.UniqueProductID=b.UniqueProductID&lt;/P&gt;&lt;P&gt;group by a.accountno&lt;/P&gt;&lt;P&gt;having usagedate-saledate=min(abs(usagedate-saledate)) and&lt;/P&gt;&lt;P&gt;usagedate-saledate &amp;gt;=0;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 20 Apr 2012 13:44:59 GMT</pubDate>
    <dc:creator>Haikuo</dc:creator>
    <dc:date>2012-04-20T13:44:59Z</dc:date>
    <item>
      <title>Matching a record based on Date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Matching-a-record-based-on-Date/m-p/90658#M25889</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have customer data that contains date joined with site details. But the problem with the dataset is incorrect account data as the mathing process has picked incorrect data. Below is a table showing the dataset that contains incorrect data and what the data needs to look like;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Scenario: Customer buys a product but transfer it to someone else. The problem here is the sale has been allocated the wrong account number, the &lt;STRONG&gt;correct account &lt;/STRONG&gt;number should be &lt;STRONG&gt;100 and not 3000.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need help with code that can match the UniqueProductID as the reference but to then look at the sale date and match it to the correct record in the second table. To put a little more detail, a "uniqueproductID" that is transferred will get an account number but it must be matched to the correct account number table. I'm guessing the logic will basically look at date ranges, so account no &lt;STRONG&gt;3000 started the warranty in June and 100 started in February. &lt;/STRONG&gt;The problem is there is no standard number of days after the product has been sold but we can identify the roughly which application was sold in relation to its first usage date.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" jive-data-cell="{&amp;quot;color&amp;quot;:&amp;quot;#575757&amp;quot;,&amp;quot;textAlign&amp;quot;:&amp;quot;left&amp;quot;,&amp;quot;padding&amp;quot;:&amp;quot;2&amp;quot;,&amp;quot;backgroundColor&amp;quot;:&amp;quot;transparent&amp;quot;,&amp;quot;fontFamily&amp;quot;:&amp;quot;Arial&amp;quot;}" jive-data-header="{&amp;quot;color&amp;quot;:&amp;quot;#FFFFFF&amp;quot;,&amp;quot;backgroundColor&amp;quot;:&amp;quot;#6690BC&amp;quot;,&amp;quot;textAlign&amp;quot;:&amp;quot;center&amp;quot;,&amp;quot;padding&amp;quot;:&amp;quot;2&amp;quot;}" style="width: 100%; border: #000000 1px solid;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;"&gt;&lt;STRONG&gt;AccountNo&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;"&gt;&lt;STRONG&gt;UniqueProductID&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;"&gt;&lt;STRONG&gt;SaleDate&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;"&gt;&lt;STRONG&gt;SaleID&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;&lt;STRONG&gt;3000&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1612000&lt;/TD&gt;&lt;TD style="vertical-align: auto; color: #575757; font-family: Arial; background-color: #99ccff; text-align: left; padding: 2px;"&gt;15/02/2011&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;ABXD1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3000&lt;/TD&gt;&lt;TD&gt;1612000&lt;/TD&gt;&lt;TD&gt;05/05/2011&lt;/TD&gt;&lt;TD&gt;AIIIU2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" jive-data-cell="{&amp;quot;color&amp;quot;:&amp;quot;#575757&amp;quot;,&amp;quot;textAlign&amp;quot;:&amp;quot;left&amp;quot;,&amp;quot;padding&amp;quot;:&amp;quot;2&amp;quot;,&amp;quot;backgroundColor&amp;quot;:&amp;quot;transparent&amp;quot;,&amp;quot;fontFamily&amp;quot;:&amp;quot;Arial&amp;quot;}" jive-data-header="{&amp;quot;color&amp;quot;:&amp;quot;#FFFFFF&amp;quot;,&amp;quot;backgroundColor&amp;quot;:&amp;quot;#6690BC&amp;quot;,&amp;quot;textAlign&amp;quot;:&amp;quot;center&amp;quot;,&amp;quot;padding&amp;quot;:&amp;quot;2&amp;quot;}" style="border: #000000 1px solid;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;"&gt;&lt;STRONG&gt;AccountNo&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;"&gt;&lt;STRONG&gt;UniqueProductID&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;"&gt;&lt;STRONG&gt;UsageDate&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;&lt;STRONG&gt;100&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1612000&lt;/TD&gt;&lt;TD style="vertical-align: auto; color: #575757; font-family: Arial; background-color: #99ccff; text-align: left; padding: 2px;"&gt;20/02/2011&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;3000&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1612000&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;03/06/2011&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this is clear and unfortuantely there is no saleID against the table that contains all historical account numbers which is why the usage date must be linked into SaleDate (the range of the date in relation to the next one).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Apr 2012 12:02:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Matching-a-record-based-on-Date/m-p/90658#M25889</guid>
      <dc:creator>thegraduate</dc:creator>
      <dc:date>2012-04-20T12:02:22Z</dc:date>
    </item>
    <item>
      <title>Re: Matching a record based on Date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Matching-a-record-based-on-Date/m-p/90659#M25890</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data h1;&lt;/P&gt;&lt;P&gt;input (AccountNo UniqueProductID) (:$10.) SaleDate ddmmyy10. SaleID:$10.;&lt;/P&gt;&lt;P&gt;format SaleDate ddmmyy10. ;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;3000 1612000 15/02/2011 ABXD1&lt;/P&gt;&lt;P&gt;3000 1612000 05/05/2011 AIIIU2&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data h2;&lt;/P&gt;&lt;P&gt;input (AccountNo UniqueProductID) (:$10.) usageDate ddmmyy10.;&lt;/P&gt;&lt;P&gt;format usageDate ddmmyy10.;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;100 1612000 20/02/2011&lt;/P&gt;&lt;P&gt;3000 1612000 03/06/2011&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*if your real data lays just as what you have shown: sorted, 1:1 ratio within the same accountno, then:*/&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;merge h1 h2;&lt;/P&gt;&lt;P&gt;by uniqueproductid;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*otherwise, not as efficient, but the following should work*/&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.accountno, a.UniqueProductID, saledate, usagedate, saleid from&lt;/P&gt;&lt;P&gt;h2 a&lt;/P&gt;&lt;P&gt;left join h1 b&lt;/P&gt;&lt;P&gt;on a.UniqueProductID=b.UniqueProductID&lt;/P&gt;&lt;P&gt;group by a.accountno&lt;/P&gt;&lt;P&gt;having usagedate-saledate=min(abs(usagedate-saledate)) and&lt;/P&gt;&lt;P&gt;usagedate-saledate &amp;gt;=0;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Apr 2012 13:44:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Matching-a-record-based-on-Date/m-p/90659#M25890</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-04-20T13:44:59Z</dc:date>
    </item>
    <item>
      <title>Re: Matching a record based on Date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Matching-a-record-based-on-Date/m-p/90660#M25891</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the reply Haikuo,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That didn't seem to work as it showed both account numbers for that sale. What you have to remember is, the account number has wrongly been allocated already. Is it possible to create a variable that says "correct" or "incorrect"?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Apr 2012 14:33:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Matching-a-record-based-on-Date/m-p/90660#M25891</guid>
      <dc:creator>thegraduate</dc:creator>
      <dc:date>2012-04-20T14:33:20Z</dc:date>
    </item>
    <item>
      <title>Re: Matching a record based on Date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Matching-a-record-based-on-Date/m-p/90661#M25892</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The best way to get the answer you want on the forum is to lay out 1) your inputting data, you already have this. 2) your output data. At this point, please provide an example of what you are exactly expecting for.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Apr 2012 15:07:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Matching-a-record-based-on-Date/m-p/90661#M25892</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-04-20T15:07:47Z</dc:date>
    </item>
    <item>
      <title>Re: Matching a record based on Date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Matching-a-record-based-on-Date/m-p/90662#M25893</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;But if there were multi observations in Second dataset between the date and&amp;nbsp; the next one at the First dataset,&lt;/P&gt;&lt;P&gt;What you are going to do?&lt;/P&gt;&lt;P&gt;Assuming You only want the closest date .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data h1;
input (AccountNo UniqueProductID) (:$10.) SaleDate ddmmyy10. SaleID:$10.;
format SaleDate ddmmyy10. ;
cards;
3000 1612000 15/02/2011 ABXD1
3000 1612000 05/05/2011 AIIIU2
;
run;
data h2;
input (AccountNo UniqueProductID) (:$10.) usageDate ddmmyy10.;
format usageDate ddmmyy10.;
cards;
100 1612000 20/02/2011
3000 1612000 03/06/2011
;
run;

proc sql;
 create table want as
&amp;nbsp; select b.AccountNo,a.UniqueProductID,a.SaleDate,a.SaleID
&amp;nbsp;&amp;nbsp; from h1 as a,h2 as b
&amp;nbsp;&amp;nbsp;&amp;nbsp; where a.AccountNo=b.AccountNo 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by a.AccountNo,SaleDate 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; having usageDate-SaleDate=min(abs(usageDate-SaleDate));
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;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Apr 2012 03:03:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Matching-a-record-based-on-Date/m-p/90662#M25893</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-04-23T03:03:45Z</dc:date>
    </item>
    <item>
      <title>Re: Matching a record based on Date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Matching-a-record-based-on-Date/m-p/90663#M25894</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If I understand you correctly, the account numbers in the first table listed in your post are incorrect. You need to match the uniqueproductid from the first table to the second table and return the accountno from the second table that has the closest usagedate &lt;SPAN style="text-decoration: underline;"&gt;after&lt;/SPAN&gt; the saledate. I think this may be what you are looking for. I added another product to your sales data without a matching warranty record.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data sales;&lt;BR /&gt;input UniqueProductID :$10. SaleDate ddmmyy10. SaleID:$10.;&lt;BR /&gt;format SaleDate ddmmyy10. ;&lt;BR /&gt;cards;&lt;BR /&gt;1612000 15/02/2011 ABXD1&lt;BR /&gt;1612000 05/05/2011 AIIIU2&lt;BR /&gt;1613333 01/04/2012 XXXXX&lt;BR /&gt;;&lt;BR /&gt; &lt;BR /&gt;data warranties;&lt;BR /&gt;input (AccountNo UniqueProductID) (:$10.) usageDate ddmmyy10.;&lt;BR /&gt;format usageDate ddmmyy10.;&lt;BR /&gt;cards;&lt;BR /&gt;100 1612000 20/02/2011&lt;BR /&gt;3000 1612000 03/06/2011&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select&lt;BR /&gt;&amp;nbsp;&amp;nbsp; b.accountno,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; a.*&lt;BR /&gt;from&lt;BR /&gt;&amp;nbsp;&amp;nbsp; sales&amp;nbsp; a&lt;BR /&gt;&amp;nbsp;&amp;nbsp; left join&lt;BR /&gt;&amp;nbsp;&amp;nbsp; warranties&amp;nbsp; b&lt;BR /&gt;&amp;nbsp;&amp;nbsp; on&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.uniqueproductid = b.uniqueproductid and&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b.usagedate = (select min( usagedate )&lt;BR /&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from&lt;BR /&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; warranties&lt;BR /&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where&lt;BR /&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; usagedate &amp;gt; a.saledate )&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 23 Apr 2012 15:11:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Matching-a-record-based-on-Date/m-p/90663#M25894</guid>
      <dc:creator>FloydNevseta</dc:creator>
      <dc:date>2012-04-23T15:11:59Z</dc:date>
    </item>
    <item>
      <title>Re: Matching a record based on Date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Matching-a-record-based-on-Date/m-p/90664#M25895</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you all for helping me find the solution. To answer Hai, the following output is required and is already present in the initial post;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="width: 100%; border: #000000 1px solid;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;"&gt;&lt;STRONG&gt;AccountNo&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;"&gt;&lt;STRONG&gt;UniqueproductID&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;"&gt;&lt;STRONG&gt;SaleDate&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;3000&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1612000&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;15/02/2011&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;3000&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1612000&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;05/05/2011&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;8728&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;14000288&lt;/TD&gt;&lt;TD&gt;06/09/2012&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;8728&lt;/TD&gt;&lt;TD&gt;14000288&lt;/TD&gt;&lt;TD&gt;06/01/2013&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="width: 100%; border: #000000 1px solid;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;"&gt;&lt;STRONG&gt;AccountNo&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;"&gt;&lt;STRONG&gt;&lt;STRONG&gt;UniqueproductID&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;"&gt;&lt;STRONG&gt;UsageDate&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;3000&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1612000&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;03/06/2011&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;&lt;STRONG&gt;100&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1612000&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;20/02/2011&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;8728&lt;/TD&gt;&lt;TD&gt;14000288&lt;/TD&gt;&lt;TD&gt;01/10/2012&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So, the output will show the correct account number for record one (100) and not 3000. I have also added one more scenario, if a sale is made on a product but the account has not been created, it should blank out the account no. So Essentially the sale must be matched to the correct account number&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Apr 2012 15:58:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Matching-a-record-based-on-Date/m-p/90664#M25895</guid>
      <dc:creator>thegraduate</dc:creator>
      <dc:date>2012-04-25T15:58:33Z</dc:date>
    </item>
    <item>
      <title>Re: Matching a record based on Date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Matching-a-record-based-on-Date/m-p/90665#M25896</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The same solution I offered earlier still works. Try it:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data sales;&lt;BR /&gt;input UniqueProductID :$10. SaleDate ddmmyy10. SaleID:$10.;&lt;BR /&gt;format SaleDate ddmmyy10. ;&lt;BR /&gt;cards;&lt;BR /&gt;1612000 15/02/2011 ABXD1&lt;BR /&gt;1612000 05/05/2011 AIIIU2&lt;BR /&gt;14000288 06/09/2012 XXXXX&lt;BR /&gt;14000288 06/01/2013 XXXXX&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data warranties;&lt;BR /&gt;input (AccountNo UniqueProductID) (:$10.) usageDate ddmmyy10.;&lt;BR /&gt;format usageDate ddmmyy10.;&lt;BR /&gt;cards;&lt;BR /&gt;100 1612000 20/02/2011&lt;BR /&gt;3000 1612000 03/06/2011&lt;BR /&gt;8728 14000288 01/10/2012 &lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select&lt;BR /&gt;&amp;nbsp;&amp;nbsp; b.accountno,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; a.*&lt;BR /&gt;from&lt;BR /&gt;&amp;nbsp;&amp;nbsp; sales&amp;nbsp; a&lt;BR /&gt;&amp;nbsp;&amp;nbsp; left join&lt;BR /&gt;&amp;nbsp;&amp;nbsp; warranties&amp;nbsp; b&lt;BR /&gt;&amp;nbsp;&amp;nbsp; on&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.uniqueproductid = b.uniqueproductid and&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b.usagedate = (select min( usagedate )&lt;BR /&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from&lt;BR /&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; warranties&lt;BR /&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where&lt;BR /&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; usagedate &amp;gt; a.saledate )&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Apr 2012 16:36:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Matching-a-record-based-on-Date/m-p/90665#M25896</guid>
      <dc:creator>FloydNevseta</dc:creator>
      <dc:date>2012-04-25T16:36:51Z</dc:date>
    </item>
    <item>
      <title>Re: Matching a record based on Date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Matching-a-record-based-on-Date/m-p/90666#M25897</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tried the following code;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: navy; background: white; font-family: 'Courier New';"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/SPAN&gt; &lt;SPAN style="color: navy; background: white; font-family: 'Courier New';"&gt;&lt;STRONG&gt;SQL&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: blue; font-family: 'Courier New';"&gt;create&lt;/SPAN&gt; &lt;SPAN style="background: white; color: blue; font-family: 'Courier New';"&gt;table&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt; identifyAccNo &lt;/SPAN&gt;&lt;SPAN style="background: white; color: blue; font-family: 'Courier New';"&gt;AS&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background: white; color: blue; font-family: 'Courier New';"&gt;select&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt; b.account_no, b.meter_number, b.invoice_date &lt;/SPAN&gt;&lt;SPAN style="background: white; color: blue; font-family: 'Courier New';"&gt;from&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; work.MasterSupplyStartDate_ b &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background: white; color: blue; font-family: 'Courier New';"&gt;left&lt;/SPAN&gt; &lt;SPAN style="background: white; color: blue; font-family: 'Courier New';"&gt;join&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt; bhyatm.ACQUISITIONMASTERACNO_20120326 A on a.meter_number=b.meter_number&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background: white; color: blue; font-family: 'Courier New';"&gt;group&lt;/SPAN&gt; &lt;SPAN style="background: white; color: blue; font-family: 'Courier New';"&gt;by&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt; b.account_no&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="background: white; color: blue; font-family: 'Courier New';"&gt;having&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt; invoice_date-finaldatecombined=min(abs(invoice_date-finaldatecombined)) And&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; invoice_date-finaldatecombined&amp;gt;=&lt;/SPAN&gt;&lt;SPAN style="color: teal; background: white; font-family: 'Courier New';"&gt;&lt;STRONG&gt;0&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: navy; background: white; font-family: 'Courier New';"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So Currently an example of what is happening with the above code;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;table A (sale data):&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="width: 100%; border: #000000 1px solid;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;"&gt;&lt;STRONG&gt;AccountNo&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;"&gt;&lt;STRONG&gt;Meter_Number&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;"&gt;&lt;STRONG&gt;finaldatecombined(sale date)&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;"&gt;&lt;STRONG&gt;SaleID&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;80000&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;55393810&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;11/06/2011&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;FX111&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;table B (supply data)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="width: 100%; border: #000000 1px solid;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;"&gt;&lt;STRONG&gt;AccountNo&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;"&gt;&lt;STRONG&gt;Meter_Number&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;"&gt;&lt;STRONG&gt;Invoice_Date&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;31000&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;55393810&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;04/10/2011&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;39000&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;55393810&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;24/10/2011&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The code mentioned at the top is bringing back both records (i.e. it is duplicating the saleid with both account numbers), this is shown below. I only want it to bring back &lt;STRONG&gt;31000 which is the closest account number to the invoice date.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="width: 100%; border: #000000 1px solid;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;"&gt;&lt;STRONG&gt;&lt;STRONG&gt;AccountNo&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;"&gt;&lt;STRONG&gt;&lt;STRONG&gt;Meter_Number&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;"&gt;&lt;STRONG&gt;&lt;STRONG&gt;finaldatecombined(sale date)&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;"&gt;&lt;STRONG&gt;&lt;STRONG&gt;SaleID&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;31000&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;55393810&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;11/06/2011&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;FX111&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;39000&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;55393810&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;11/06/2011&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;FX111&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 May 2012 10:43:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Matching-a-record-based-on-Date/m-p/90666#M25897</guid>
      <dc:creator>thegraduate</dc:creator>
      <dc:date>2012-05-09T10:43:26Z</dc:date>
    </item>
    <item>
      <title>Re: Matching a record based on Date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Matching-a-record-based-on-Date/m-p/90667#M25898</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's my third attempt to get you to try this. Trust me. It works. I modified it to use the data structure of your last post, but the concept is the same as the other 2 times I offered this solution.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data A;&lt;BR /&gt;infile cards;&lt;BR /&gt;input accountno meter_number finaldatecombined ddmmyy10. saleid $;&lt;BR /&gt;format finaldatecombined ddmmyy10.;&lt;BR /&gt;cards;&lt;BR /&gt;80000 55393810 11/06/2011 FX111&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data B;&lt;BR /&gt;infile cards;&lt;BR /&gt;input accountno meter_number invoice_date ddmmyy10.;&lt;BR /&gt;format invoice_date ddmmyy10.;&lt;BR /&gt;cards;&lt;BR /&gt;31000 55393810 04/10/2011&lt;BR /&gt;39000 55393810 24/10/2011 &lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table identifyaccno as&lt;BR /&gt;select&lt;BR /&gt;&amp;nbsp;&amp;nbsp; b.accountno,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; a.meter_number,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; a.finaldatecombined,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; b.invoice_date,&lt;BR /&gt;&amp;nbsp;&amp;nbsp; a.saleid&lt;BR /&gt;from&lt;BR /&gt;&amp;nbsp;&amp;nbsp; a&lt;BR /&gt;&amp;nbsp;&amp;nbsp; left join&lt;BR /&gt;&amp;nbsp;&amp;nbsp; b&lt;BR /&gt;&amp;nbsp;&amp;nbsp; on&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a.meter_number = b.meter_number and&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b.invoice_date = (select min( invoice_date )&lt;BR /&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from&lt;BR /&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b&lt;BR /&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where&lt;BR /&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; b.invoice_date &amp;gt; a.finaldatecombined )&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 May 2012 15:10:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Matching-a-record-based-on-Date/m-p/90667#M25898</guid>
      <dc:creator>FloydNevseta</dc:creator>
      <dc:date>2012-05-09T15:10:01Z</dc:date>
    </item>
    <item>
      <title>Re: Matching a record based on Date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Matching-a-record-based-on-Date/m-p/90668#M25899</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Mr Bigot,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tried your code and it returned blank values for account_no and invoice_Date;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-size: 11pt; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; background: white; font-size: 11pt; font-family: 'Courier New';"&gt;sql&lt;/STRONG&gt;&lt;SPAN style="font-size: 11pt; background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 11pt; background: white; color: blue; font-family: 'Courier New';"&gt;create&lt;/SPAN&gt; &lt;SPAN style="font-size: 11pt; background: white; color: blue; font-family: 'Courier New';"&gt;table&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background: white; color: black; font-family: 'Courier New';"&gt; identifyaccno &lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background: white; color: blue; font-family: 'Courier New';"&gt;as&lt;/SPAN&gt;&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; &lt;SPAN style="font-size: 11pt; background: white; color: blue; font-family: 'Courier New';"&gt;select&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11pt; background: white; color: black; font-family: 'Courier New';"&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;&amp;nbsp; b.account_no,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11pt; background: white; color: black; font-family: 'Courier New';"&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;&amp;nbsp; a.meter_number,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11pt; background: white; color: black; font-family: 'Courier New';"&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;&amp;nbsp; a.finaldatecombined,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11pt; background: white; color: black; font-family: 'Courier New';"&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;&amp;nbsp; b.invoice_date,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11pt; background: white; color: black; font-family: 'Courier New';"&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;&amp;nbsp; a.salesforce_id&lt;/SPAN&gt;&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; &lt;SPAN style="font-size: 11pt; background: white; color: blue; font-family: 'Courier New';"&gt;from&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11pt; background: white; color: black; font-family: 'Courier New';"&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;&amp;nbsp; bhyatm.ACQUISITIONMASTERACNO_20120326 a&lt;/SPAN&gt;&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; &lt;SPAN style="font-size: 11pt; background: white; color: blue; font-family: 'Courier New';"&gt;left&lt;/SPAN&gt; &lt;SPAN style="font-size: 11pt; background: white; color: blue; font-family: 'Courier New';"&gt;join&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11pt; background: white; color: black; font-family: 'Courier New';"&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;&amp;nbsp; MasterSupplyStartDate_ b&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11pt; background: white; color: black; font-family: 'Courier New';"&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;&amp;nbsp; on&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11pt; background: white; color: black; font-family: 'Courier New';"&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;&amp;nbsp; a.meter_number = b.meter_number and&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11pt; background: white; color: black; font-family: 'Courier New';"&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;&amp;nbsp; b.invoice_date = (&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background: white; color: blue; font-family: 'Courier New';"&gt;select&lt;/SPAN&gt;&lt;SPAN style="font-size: 11pt; background: white; color: black; font-family: 'Courier New';"&gt; min(invoice_date)&lt;/SPAN&gt;&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; &lt;SPAN style="font-size: 11pt; background: white; color: blue; font-family: 'Courier New';"&gt;from&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11pt; background: white; color: black; font-family: 'Courier New';"&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;&amp;nbsp; MasterSupplyStartDate_ b&lt;/SPAN&gt;&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; &lt;SPAN style="font-size: 11pt; background: white; color: blue; font-family: 'Courier New';"&gt;where&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11pt; background: white; color: black; font-family: 'Courier New';"&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;&amp;nbsp; b.invoice_date &amp;gt; a.finaldatecombined)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 11pt; background: white; color: black; font-family: 'Courier New';"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; background: white; font-size: 11pt; font-family: 'Courier New';"&gt;quit&lt;/STRONG&gt;&lt;SPAN style="font-size: 11pt; background: white; color: black; font-family: 'Courier New';"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Have I made a mistake?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2012 08:26:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Matching-a-record-based-on-Date/m-p/90668#M25899</guid>
      <dc:creator>thegraduate</dc:creator>
      <dc:date>2012-05-10T08:26:58Z</dc:date>
    </item>
    <item>
      <title>Re: Matching a record based on Date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Matching-a-record-based-on-Date/m-p/90669#M25900</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In an earlier post, you mentioned that if a sale has been made but the account_no has not been created yet that the account_no should be blank. The SQL i wrote has an outer join (left join) so that if there are no matching account numbers they would be blank. For those records with a missing account_no, have you confirmed that the meter has a valid match on the b table?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 May 2012 11:42:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Matching-a-record-based-on-Date/m-p/90669#M25900</guid>
      <dc:creator>FloydNevseta</dc:creator>
      <dc:date>2012-05-10T11:42:27Z</dc:date>
    </item>
  </channel>
</rss>

