<?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: Join two tables by date falls into the range of dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Join-two-tables-by-date-falls-into-the-range-of-dates/m-p/894228#M353242</link>
    <description>&lt;P&gt;I know its well over 5 years since your post but if you're still troubled by this I think you should look into the CASE statement&lt;/P&gt;</description>
    <pubDate>Thu, 14 Sep 2023 08:57:01 GMT</pubDate>
    <dc:creator>RoyBelderok</dc:creator>
    <dc:date>2023-09-14T08:57:01Z</dc:date>
    <item>
      <title>Join two tables by date falls into the range of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-two-tables-by-date-falls-into-the-range-of-dates/m-p/444341#M111229</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two tables: a &amp;amp; b.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table a:&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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Location |&amp;nbsp; Date_1 |&amp;nbsp; Price&lt;/P&gt;&lt;P&gt;------------------------------------&lt;/P&gt;&lt;P&gt;L1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp;&amp;nbsp;09/08&amp;nbsp; &amp;nbsp;|&amp;nbsp; &amp;nbsp;104&lt;/P&gt;&lt;P&gt;------------------------------------&lt;/P&gt;&lt;P&gt;L1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp; 09/09&amp;nbsp; &amp;nbsp;|&amp;nbsp; &amp;nbsp;134&lt;/P&gt;&lt;P&gt;------------------------------------&lt;/P&gt;&lt;P&gt;L1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp; 09/10&amp;nbsp; &amp;nbsp;|&amp;nbsp; &amp;nbsp; 78&lt;/P&gt;&lt;P&gt;------------------------------------&lt;/P&gt;&lt;P&gt;.........................................&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table b:&lt;/P&gt;&lt;P&gt;Location |&amp;nbsp; Start_Date&amp;nbsp;|&amp;nbsp; End_Date&amp;nbsp; | Season_Id&lt;/P&gt;&lt;P&gt;---------------------------------------------------------------&lt;/P&gt;&lt;P&gt;L1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp;&amp;nbsp;09/07&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp; 09/09&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;---------------------------------------------------------------&lt;/P&gt;&lt;P&gt;L1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp; 09/10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp; &amp;nbsp;11/30&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;---------------------------------------------------------------&lt;/P&gt;&lt;P&gt;L1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp; 12/01&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp; &amp;nbsp;12/31&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;---------------------------------------------------------------&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;L1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp;&amp;nbsp;01&lt;/SPAN&gt;&lt;SPAN&gt;/01&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp; &amp;nbsp;09/06&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; 4&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I would like to&amp;nbsp;join table a and table b: when 'Date_1' in table a falls in the range of 'Start_Date' &amp;amp; 'End_Date' in table b, corresponding 'Season_Id' could be added to a particular row.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Want:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Location |&amp;nbsp; Date_1 |&amp;nbsp; Price&amp;nbsp; |&amp;nbsp; Season_Id&lt;/P&gt;&lt;P&gt;------------------------------------------------------&lt;/P&gt;&lt;P&gt;L1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp;&amp;nbsp;09/08&amp;nbsp; &amp;nbsp;|&amp;nbsp; &amp;nbsp;104&amp;nbsp; &amp;nbsp;|&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;------------------------------------------------------&lt;/P&gt;&lt;P&gt;L1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp; 09/09&amp;nbsp; &amp;nbsp;|&amp;nbsp; &amp;nbsp;134&amp;nbsp; &amp;nbsp;|&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;------------------------------------------------------&lt;/P&gt;&lt;P&gt;L1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;|&amp;nbsp; 09/10&amp;nbsp; &amp;nbsp;|&amp;nbsp; &amp;nbsp; 78&amp;nbsp; &amp;nbsp; |&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;------------------------------------------------------&lt;/P&gt;&lt;P&gt;..............................................................&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My sas code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
	 	Create Table Want as select 
			A.*, B.Season_Id from  A,  B
			where A.Date_1 &amp;gt;= B.Start_Date and A.Date_1 &amp;lt;= B.End_Date
			and A.Location = B.Location;
	Quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But it returns an empty table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How could I fix it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Sat, 10 Mar 2018 03:47:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-two-tables-by-date-falls-into-the-range-of-dates/m-p/444341#M111229</guid>
      <dc:creator>Crubal</dc:creator>
      <dc:date>2018-03-10T03:47:01Z</dc:date>
    </item>
    <item>
      <title>Re: Join two tables by date falls into the range of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-two-tables-by-date-falls-into-the-range-of-dates/m-p/444353#M111239</link>
      <description>&lt;P&gt;The condition as such looks o.k. to me and should return rows so I assume something isn't o.k. with your variables. Are the Date variables numeric and do they contain SAS date values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want us to post actually working and tested SAS code: Please post your sample data as a tested&amp;nbsp;SAS data step creating the sample data.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Mar 2018 05:50:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-two-tables-by-date-falls-into-the-range-of-dates/m-p/444353#M111239</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-03-10T05:50:29Z</dc:date>
    </item>
    <item>
      <title>Re: Join two tables by date falls into the range of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-two-tables-by-date-falls-into-the-range-of-dates/m-p/444354#M111240</link>
      <description>By optical examining it looks ok, even if your dates are treated as strings.&lt;BR /&gt;Please attach your data as datalines if you want someone else to try your code.</description>
      <pubDate>Sat, 10 Mar 2018 05:54:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-two-tables-by-date-falls-into-the-range-of-dates/m-p/444354#M111240</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2018-03-10T05:54:27Z</dc:date>
    </item>
    <item>
      <title>Re: Join two tables by date falls into the range of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-two-tables-by-date-falls-into-the-range-of-dates/m-p/444375#M111246</link>
      <description>&lt;P&gt;Your code works with example data made from your tables. So your datasets must differ from what you gave us.&lt;/P&gt;</description>
      <pubDate>Sat, 10 Mar 2018 11:04:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-two-tables-by-date-falls-into-the-range-of-dates/m-p/444375#M111246</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-10T11:04:48Z</dc:date>
    </item>
    <item>
      <title>Re: Join two tables by date falls into the range of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-two-tables-by-date-falls-into-the-range-of-dates/m-p/444411#M111261</link>
      <description>Thanks! I output my data into excel and found that my date is actually 03/09/2017. As I used 'mmddyy5.' format for 'Date_1' in table a, and It actually has year information. Table b has different year information. So that I cannot match.</description>
      <pubDate>Sat, 10 Mar 2018 16:21:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-two-tables-by-date-falls-into-the-range-of-dates/m-p/444411#M111261</guid>
      <dc:creator>Crubal</dc:creator>
      <dc:date>2018-03-10T16:21:47Z</dc:date>
    </item>
    <item>
      <title>Re: Join two tables by date falls into the range of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-two-tables-by-date-falls-into-the-range-of-dates/m-p/444412#M111262</link>
      <description>&lt;P&gt;You are right, actually although in SAS date is in (month / date) format, it has year information if I output to excel.&amp;nbsp;And year cannot match.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Mar 2018 16:23:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-two-tables-by-date-falls-into-the-range-of-dates/m-p/444412#M111262</guid>
      <dc:creator>Crubal</dc:creator>
      <dc:date>2018-03-10T16:23:18Z</dc:date>
    </item>
    <item>
      <title>Re: Join two tables by date falls into the range of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-two-tables-by-date-falls-into-the-range-of-dates/m-p/444413#M111263</link>
      <description>Thanks for your reminding. It is resolved if I output the dataset into excel. As it has year information but I shortcut it to 'mmddyy5.' to let it show just month and date.</description>
      <pubDate>Sat, 10 Mar 2018 16:24:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-two-tables-by-date-falls-into-the-range-of-dates/m-p/444413#M111263</guid>
      <dc:creator>Crubal</dc:creator>
      <dc:date>2018-03-10T16:24:44Z</dc:date>
    </item>
    <item>
      <title>Re: Join two tables by date falls into the range of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-two-tables-by-date-falls-into-the-range-of-dates/m-p/444487#M111298</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/50019"&gt;@Crubal&lt;/a&gt;&amp;nbsp;It would technically be possible to join just on the day and month part of a date - but I guess that wouldn't make business sense.&lt;/P&gt;</description>
      <pubDate>Sun, 11 Mar 2018 00:40:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-two-tables-by-date-falls-into-the-range-of-dates/m-p/444487#M111298</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-03-11T00:40:45Z</dc:date>
    </item>
    <item>
      <title>Re: Join two tables by date falls into the range of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-two-tables-by-date-falls-into-the-range-of-dates/m-p/444642#M111349</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/50019"&gt;@Crubal&lt;/a&gt; wrote:&lt;BR /&gt;Thanks! I output my data into excel and found that my date is actually 03/09/2017. As I used 'mmddyy5.' format for 'Date_1' in table a, and It actually has year information. Table b has different year information. So that I cannot match.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I can only repeat the same old, same old:&lt;/P&gt;
&lt;P&gt;POST EXAMPLE DATA IN A DATA STEP WITH DATALINES!&lt;/P&gt;
&lt;P&gt;Without solid example data, all our attempts at helping you are just guesswork, and lack of such eample data only causes a totally unnecessary delay in the path to a solution.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Mar 2018 06:27:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-two-tables-by-date-falls-into-the-range-of-dates/m-p/444642#M111349</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-12T06:27:09Z</dc:date>
    </item>
    <item>
      <title>Re: Join two tables by date falls into the range of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-two-tables-by-date-falls-into-the-range-of-dates/m-p/592636#M169945</link>
      <description>&lt;A href="https://pdfs.semanticscholar.org/dc07/8531d26794c3ca8a5079c8abc451eef4eedd.pdf" target="_blank"&gt;https://pdfs.semanticscholar.org/dc07/8531d26794c3ca8a5079c8abc451eef4eedd.pdf&lt;/A&gt; this is a good paper</description>
      <pubDate>Mon, 30 Sep 2019 11:57:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-two-tables-by-date-falls-into-the-range-of-dates/m-p/592636#M169945</guid>
      <dc:creator>Filipvdr</dc:creator>
      <dc:date>2019-09-30T11:57:15Z</dc:date>
    </item>
    <item>
      <title>Re: Join two tables by date falls into the range of dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Join-two-tables-by-date-falls-into-the-range-of-dates/m-p/894228#M353242</link>
      <description>&lt;P&gt;I know its well over 5 years since your post but if you're still troubled by this I think you should look into the CASE statement&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2023 08:57:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Join-two-tables-by-date-falls-into-the-range-of-dates/m-p/894228#M353242</guid>
      <dc:creator>RoyBelderok</dc:creator>
      <dc:date>2023-09-14T08:57:01Z</dc:date>
    </item>
  </channel>
</rss>

