<?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: vlookup by most recent date in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/vlookup-by-most-recent-date/m-p/578526#M13363</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data table1;
input customer $ state $ doj :ddmmyy10.;
format doj ddmmyy10.;
cards;
Adam CA 1/1/2017
Carllos TX 1/1/2018
Adam CA 1/1/2019
run;

data table2;
input State $ Date_Effective :ddmmyy10.  Discount;
format Date_Effective ddmmyy10.;
cards;
CA 1/1/2015  5
CA 1/1/2018  10
TX 1/1/2014  2
TX 1/1/2017  3
TX 1/1/2019  4
run;

proc sort data=table2;
	by State descending Date_Effective;
run;

data table3;
	Set table1 ;
	do i=1 to nbs;
		set table2(rename=(state=state_ )) nobs=nbs point=i;
		if state=state_ and Date_Effective &amp;lt;=doj then do;
			output;	leave;	
		end;
	end;	
	drop state_ Date_Effective;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 01 Aug 2019 18:31:39 GMT</pubDate>
    <dc:creator>r_behata</dc:creator>
    <dc:date>2019-08-01T18:31:39Z</dc:date>
    <item>
      <title>vlookup by most recent date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/vlookup-by-most-recent-date/m-p/578522#M13362</link>
      <description>&lt;P&gt;I have 2 tables. I am trying to extract information from table 2 using the date value from table 1 and finding the most recent corresponding date on table 2 (that's less than the date on table 1). I'm not sure how to add tables on this forum, so please advice me, but I will type a rough outline of the table here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lets assume we're talking about applying discounts to a gym membership.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table 1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Customer&amp;nbsp;&amp;nbsp; State&amp;nbsp;&amp;nbsp;&amp;nbsp; Date Joined &lt;/U&gt;&lt;/P&gt;&lt;P&gt;Adam&amp;nbsp; CA&amp;nbsp;&amp;nbsp; 1/1/2017&lt;/P&gt;&lt;P&gt;Carllos TX 1/1/2018&lt;/P&gt;&lt;P&gt;Adam CA 1/1/2019&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table 2 Discounts&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;State&amp;nbsp; &amp;nbsp;Date Effective&amp;nbsp;&amp;nbsp; Discount&lt;/U&gt;&lt;/P&gt;&lt;P&gt;CA 1/1/2015&amp;nbsp; 5%&lt;/P&gt;&lt;P&gt;CA 1/1/2018&amp;nbsp; 10%&lt;/P&gt;&lt;P&gt;TX 1/1/2014&amp;nbsp; 2%&lt;/P&gt;&lt;P&gt;TX 1/1/2017 3%&lt;/P&gt;&lt;P&gt;TX 1/1/2019 4%&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The final table should look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;Customer&amp;nbsp;&amp;nbsp; State&amp;nbsp;&amp;nbsp;&amp;nbsp; Date Joined&amp;nbsp;&amp;nbsp; Effective Discount&lt;/U&gt;&lt;/P&gt;&lt;P&gt;Adam&amp;nbsp; CA&amp;nbsp;&amp;nbsp; 1/1/2017&amp;nbsp;&amp;nbsp;&amp;nbsp; 5%&lt;/P&gt;&lt;P&gt;Carllos TX 1/1/2018&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 3%&lt;/P&gt;&lt;P&gt;Adam CA 1/1/2019&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 10%&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2019 17:58:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/vlookup-by-most-recent-date/m-p/578522#M13362</guid>
      <dc:creator>toesockshoe</dc:creator>
      <dc:date>2019-08-01T17:58:34Z</dc:date>
    </item>
    <item>
      <title>Re: vlookup by most recent date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/vlookup-by-most-recent-date/m-p/578526#M13363</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data table1;
input customer $ state $ doj :ddmmyy10.;
format doj ddmmyy10.;
cards;
Adam CA 1/1/2017
Carllos TX 1/1/2018
Adam CA 1/1/2019
run;

data table2;
input State $ Date_Effective :ddmmyy10.  Discount;
format Date_Effective ddmmyy10.;
cards;
CA 1/1/2015  5
CA 1/1/2018  10
TX 1/1/2014  2
TX 1/1/2017  3
TX 1/1/2019  4
run;

proc sort data=table2;
	by State descending Date_Effective;
run;

data table3;
	Set table1 ;
	do i=1 to nbs;
		set table2(rename=(state=state_ )) nobs=nbs point=i;
		if state=state_ and Date_Effective &amp;lt;=doj then do;
			output;	leave;	
		end;
	end;	
	drop state_ Date_Effective;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Aug 2019 18:31:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/vlookup-by-most-recent-date/m-p/578526#M13363</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2019-08-01T18:31:39Z</dc:date>
    </item>
    <item>
      <title>Re: vlookup by most recent date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/vlookup-by-most-recent-date/m-p/578527#M13364</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data one;
input Customer $  State $   DateJoined :mmddyy10.;
format DateJoined mmddyy10.;
cards;
Adam  CA   1/1/2017
Carllos TX 1/1/2018
Adam CA 1/1/2019
;


data two;
input State $  DateEffective  :mmddyy10. Discount :percent.;
format DateEffective  mmddyy10. discount percent5.;
cards;
CA 1/1/2015  5%
CA 1/1/2018  10%
TX 1/1/2014  2%
TX 1/1/2017 3%
TX 1/1/2019 4%
;

proc sql;
create table want as
select a.*,Discount
from one a, two b
where a.state=b.state and a.DateJoined&amp;gt;=DateEffective
group by customer,a.state,datejoined
having max(DateEffective)=DateEffective
order by datejoined;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Aug 2019 18:34:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/vlookup-by-most-recent-date/m-p/578527#M13364</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-01T18:34:19Z</dc:date>
    </item>
    <item>
      <title>Re: vlookup by most recent date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/vlookup-by-most-recent-date/m-p/578564#M13375</link>
      <description>&lt;P&gt;thanks for your response.... do you mind explaining the logic on the where statement? How come there is no join anywhere... sorry I'm just picking up SAS after a year and my knowledge is pretty raw&lt;/P&gt;</description>
      <pubDate>Thu, 01 Aug 2019 20:22:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/vlookup-by-most-recent-date/m-p/578564#M13375</guid>
      <dc:creator>toesockshoe</dc:creator>
      <dc:date>2019-08-01T20:22:15Z</dc:date>
    </item>
    <item>
      <title>Re: vlookup by most recent date</title>
      <link>https://communities.sas.com/t5/New-SAS-User/vlookup-by-most-recent-date/m-p/578571#M13377</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/218524"&gt;@toesockshoe&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The syntax is equivalent to&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want1 as
select a.*,Discount
from one a left join two b
on a.state=b.state and a.DateJoined&amp;gt;=DateEffective
group by customer,a.state,datejoined
having max(DateEffective)=DateEffective
order by datejoined;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Aug 2019 21:01:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/vlookup-by-most-recent-date/m-p/578571#M13377</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-08-01T21:01:24Z</dc:date>
    </item>
  </channel>
</rss>

