<?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 Left join not working in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Left-join-not-working/m-p/254752#M56993</link>
    <description>&lt;P&gt;Hi I have two tables. That I want to do a left join &amp;nbsp;and its bringing in only data where it's equal &amp;nbsp;enclose is an example of code&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table temp2 as&lt;/P&gt;&lt;P&gt;select table1.*, table2.id , table2.date&lt;/P&gt;&lt;P&gt;from table1,table2&lt;/P&gt;&lt;P&gt;where table1.id=table2.id and table2.date Gt table1.date&lt;/P&gt;&lt;P&gt;group by table1.id&lt;/P&gt;&lt;P&gt;having table2.date-table1.date=min(table2.date-table1.date);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;create table want as&lt;/P&gt;&lt;P&gt;select temp2.*,table2.id ,table2. Date&lt;/P&gt;&lt;P&gt;from temp2,table2&lt;/P&gt;&lt;P&gt;where temp2.id=table2.id and table2.date gt temp2.date&lt;/P&gt;&lt;P&gt;group by temp2.id&lt;/P&gt;&lt;P&gt;having table2.date-temp2.date=min(table2.date-temp2.date)&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i did did use the left join it didn't work &amp;nbsp;thanks for assistance&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 05 Mar 2016 17:47:44 GMT</pubDate>
    <dc:creator>Beto16</dc:creator>
    <dc:date>2016-03-05T17:47:44Z</dc:date>
    <item>
      <title>Left join not working</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Left-join-not-working/m-p/254752#M56993</link>
      <description>&lt;P&gt;Hi I have two tables. That I want to do a left join &amp;nbsp;and its bringing in only data where it's equal &amp;nbsp;enclose is an example of code&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table temp2 as&lt;/P&gt;&lt;P&gt;select table1.*, table2.id , table2.date&lt;/P&gt;&lt;P&gt;from table1,table2&lt;/P&gt;&lt;P&gt;where table1.id=table2.id and table2.date Gt table1.date&lt;/P&gt;&lt;P&gt;group by table1.id&lt;/P&gt;&lt;P&gt;having table2.date-table1.date=min(table2.date-table1.date);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;create table want as&lt;/P&gt;&lt;P&gt;select temp2.*,table2.id ,table2. Date&lt;/P&gt;&lt;P&gt;from temp2,table2&lt;/P&gt;&lt;P&gt;where temp2.id=table2.id and table2.date gt temp2.date&lt;/P&gt;&lt;P&gt;group by temp2.id&lt;/P&gt;&lt;P&gt;having table2.date-temp2.date=min(table2.date-temp2.date)&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i did did use the left join it didn't work &amp;nbsp;thanks for assistance&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Mar 2016 17:47:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Left-join-not-working/m-p/254752#M56993</guid>
      <dc:creator>Beto16</dc:creator>
      <dc:date>2016-03-05T17:47:44Z</dc:date>
    </item>
    <item>
      <title>Re: Left join not working</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Left-join-not-working/m-p/254753#M56994</link>
      <description>&lt;P&gt;None of the code below specifies a left join....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You also have a HAVING clause which filters data so it's not a 'straight left join'. Remove the having clause and see if you get what you expect.&lt;/P&gt;</description>
      <pubDate>Sat, 05 Mar 2016 18:03:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Left-join-not-working/m-p/254753#M56994</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-05T18:03:48Z</dc:date>
    </item>
    <item>
      <title>Re: Left join not working</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Left-join-not-working/m-p/254774#M56995</link>
      <description>&lt;P&gt;The problem is that in a left join, non matching table2 records will show table2.id and table2.date as missing which will cause the having clause to exclude them. &amp;nbsp;You can try this instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table temp2 as
select 
	table1.*, 
	table2.id as id2, 
	table2.date as date2
from 
	table1 left join
	table2 on table1.id=table2.id and table2.date gt table1.date
group by table1.id
having coalesce(table2.date,table1.date)-table1.date=min(coalesce(table2.date,table1.date)-table1.date);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 05 Mar 2016 21:07:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Left-join-not-working/m-p/254774#M56995</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-03-05T21:07:20Z</dc:date>
    </item>
    <item>
      <title>Re: Left join not working</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Left-join-not-working/m-p/254888#M57009</link>
      <description>&lt;P&gt;Hi Pgstat,&lt;/P&gt;&lt;P&gt;i tried your code with coalesce &amp;nbsp;I notice you used comma instead of minus I tried both gave me small sample ..currently table 1 has 7k records I only get 84.... What I am doing in the code is if there is match table 1 and table 2 than from table two give the next date of service for example&amp;nbsp;&lt;/P&gt;&lt;P&gt;table 1&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Date &amp;nbsp;&lt;/P&gt;&lt;P&gt;a1. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/01/16&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;table 2&amp;nbsp;&lt;/P&gt;&lt;P&gt;id. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Date&amp;nbsp;&lt;/P&gt;&lt;P&gt;a1. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/02/16&lt;/P&gt;&lt;P&gt;a1. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/06/16&lt;/P&gt;&lt;P&gt;i &amp;nbsp;want the left join to show&amp;nbsp;&lt;/P&gt;&lt;P&gt;Id. &amp;nbsp; &amp;nbsp; &amp;nbsp;Date. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Next service&amp;nbsp;&lt;/P&gt;&lt;P&gt;a1. &amp;nbsp; &amp;nbsp;01/01/16 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/02/16&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thats what I want to see what I see now is some thing like this&lt;/P&gt;&lt;P&gt;id. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Date. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Next service&lt;/P&gt;&lt;P&gt;a1. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01/1/16. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/02/16&lt;/P&gt;&lt;P&gt;a1. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/1/16. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/06/16&lt;/P&gt;&lt;P&gt;a1. &amp;nbsp; &amp;nbsp; &amp;nbsp; 01/1/16. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/09/16&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is every instance in table 2 is brought over ..hope that make sense thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Mar 2016 05:48:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Left-join-not-working/m-p/254888#M57009</guid>
      <dc:creator>Beto16</dc:creator>
      <dc:date>2016-03-07T05:48:24Z</dc:date>
    </item>
  </channel>
</rss>

