<?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 How to join/merge tables (vlookup) not based on exact match? in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-join-merge-tables-vlookup-not-based-on-exact-match/m-p/376394#M24452</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data source;
  infile datalines dlm=",";
  input date date9.;
datalines;
01JAN2015
01JAN2016
01SEP2016
;
run;

data source;
set source;
format date date9.;
run;

data ref;
  infile datalines dlm=",";
  input date2 date9.;
datalines;
01JAN2011
01JUN2016
;
run;

data ref;
set ref;
format date2 date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;After joining them, the final dataset would look like:&lt;/P&gt;&lt;P&gt;date &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;date2&lt;/P&gt;&lt;P&gt;01JAN2015 &amp;nbsp; 01JAN2011 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* because 01/01/2015 &amp;gt;= 01/01/2011 and &amp;lt; 01/06/2016 */&lt;/P&gt;&lt;P&gt;01JAN2016 &amp;nbsp; 01JAN2011&lt;/P&gt;&lt;P&gt;01SEP2016 &amp;nbsp; 01JUN2016&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Typically in Excel, one would use "=VLOOKUP($C4,$H$4:$I$5,1,TRUE)" (for the 2nd column). I believe there is a similar concept in SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to achieve it?&lt;/P&gt;</description>
    <pubDate>Mon, 17 Jul 2017 03:34:39 GMT</pubDate>
    <dc:creator>ayin</dc:creator>
    <dc:date>2017-07-17T03:34:39Z</dc:date>
    <item>
      <title>How to join/merge tables (vlookup) not based on exact match?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-join-merge-tables-vlookup-not-based-on-exact-match/m-p/376394#M24452</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data source;
  infile datalines dlm=",";
  input date date9.;
datalines;
01JAN2015
01JAN2016
01SEP2016
;
run;

data source;
set source;
format date date9.;
run;

data ref;
  infile datalines dlm=",";
  input date2 date9.;
datalines;
01JAN2011
01JUN2016
;
run;

data ref;
set ref;
format date2 date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;After joining them, the final dataset would look like:&lt;/P&gt;&lt;P&gt;date &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;date2&lt;/P&gt;&lt;P&gt;01JAN2015 &amp;nbsp; 01JAN2011 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; /* because 01/01/2015 &amp;gt;= 01/01/2011 and &amp;lt; 01/06/2016 */&lt;/P&gt;&lt;P&gt;01JAN2016 &amp;nbsp; 01JAN2011&lt;/P&gt;&lt;P&gt;01SEP2016 &amp;nbsp; 01JUN2016&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Typically in Excel, one would use "=VLOOKUP($C4,$H$4:$I$5,1,TRUE)" (for the 2nd column). I believe there is a similar concept in SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How to achieve it?&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2017 03:34:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-join-merge-tables-vlookup-not-based-on-exact-match/m-p/376394#M24452</guid>
      <dc:creator>ayin</dc:creator>
      <dc:date>2017-07-17T03:34:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to join/merge tables (vlookup) not based on exact match?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-join-merge-tables-vlookup-not-based-on-exact-match/m-p/376395#M24453</link>
      <description>&lt;P&gt;First tranpose the ref dataset and then merge with source via proc sql as below to get the expected output&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=ref out=trans;
var date2;
run;

proc sql;
create table want as select a.date, case when a.date&amp;gt;=b.col1 and a.date &amp;lt;=b.col2 then b.col1 else b.col2 end as date2 format=date9. from source as a , trans as b;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Jul 2017 03:46:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-join-merge-tables-vlookup-not-based-on-exact-match/m-p/376395#M24453</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2017-07-17T03:46:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to join/merge tables (vlookup) not based on exact match?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-join-merge-tables-vlookup-not-based-on-exact-match/m-p/376402#M24457</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12151"&gt;@Jagadishkatam&lt;/a&gt;, thank you for your quick response!&lt;/P&gt;&lt;P&gt;This approach definitely works on the simplified example above. However, in my ref dataset, the number of rows is dynamic (sometimes more than 20).&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jul 2017 04:44:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-join-merge-tables-vlookup-not-based-on-exact-match/m-p/376402#M24457</guid>
      <dc:creator>ayin</dc:creator>
      <dc:date>2017-07-17T04:44:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to join/merge tables (vlookup) not based on exact match?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-join-merge-tables-vlookup-not-based-on-exact-match/m-p/376425#M24460</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
create table temp as 
  select * from work.source, work.ref           /* cartesian product */
  where date &amp;gt; date2                                   
  order by date, date2;
quit;

data want;
set temp;
by date;
if last.date;
run;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Jul 2017 07:17:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-join-merge-tables-vlookup-not-based-on-exact-match/m-p/376425#M24460</guid>
      <dc:creator>ayin</dc:creator>
      <dc:date>2017-07-17T07:17:03Z</dc:date>
    </item>
  </channel>
</rss>

