<?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 sequence of multiple left join in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/sequence-of-multiple-left-join/m-p/254810#M56998</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to use left join to join multiple tables and I am wondering whether the order of the join matters. Say&lt;/P&gt;&lt;PRE&gt;proc sql;
create table t1 as
select * from A 
natural left join B 
natural left join C;
quit;&lt;/PRE&gt;&lt;P&gt;does this code generate the same result as&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;
create table t1 as
select * from A 
natural left join 
(select * from B natural left join C);
quit;&lt;/PRE&gt;&lt;P&gt;?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or as long as the tables A, B, and C is linked by left join in this order, the result would not change?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the above in a small trial dataset, and I got the same table. However, when I used similar multiple natural left join with the data I worked on, I got different result.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;More generally, is the following correct: A left join B left join c =&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;(A left join B) left join c =&amp;nbsp; A left join (B left join c) =&amp;nbsp; A left join D where D =&amp;nbsp;B left join c?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 06 Mar 2016 06:34:12 GMT</pubDate>
    <dc:creator>bochen</dc:creator>
    <dc:date>2016-03-06T06:34:12Z</dc:date>
    <item>
      <title>sequence of multiple left join</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sequence-of-multiple-left-join/m-p/254810#M56998</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to use left join to join multiple tables and I am wondering whether the order of the join matters. Say&lt;/P&gt;&lt;PRE&gt;proc sql;
create table t1 as
select * from A 
natural left join B 
natural left join C;
quit;&lt;/PRE&gt;&lt;P&gt;does this code generate the same result as&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;
create table t1 as
select * from A 
natural left join 
(select * from B natural left join C);
quit;&lt;/PRE&gt;&lt;P&gt;?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or as long as the tables A, B, and C is linked by left join in this order, the result would not change?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the above in a small trial dataset, and I got the same table. However, when I used similar multiple natural left join with the data I worked on, I got different result.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;More generally, is the following correct: A left join B left join c =&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;(A left join B) left join c =&amp;nbsp; A left join (B left join c) =&amp;nbsp; A left join D where D =&amp;nbsp;B left join c?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Mar 2016 06:34:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sequence-of-multiple-left-join/m-p/254810#M56998</guid>
      <dc:creator>bochen</dc:creator>
      <dc:date>2016-03-06T06:34:12Z</dc:date>
    </item>
    <item>
      <title>Re: sequence of multiple left join</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sequence-of-multiple-left-join/m-p/254820#M57000</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/74230"&gt;@bochen﻿&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a simple example which shows that the first two steps can generate different results:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
id=1; x=2;
run;

data b;
id=1; y=1;
run;

data c;
id=1; x=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The first PROC SQL step joins A and B on A.id=B.id to the intermediate result "one obs. with id=1, x=2, y=&lt;STRONG&gt;1&lt;/STRONG&gt;" (call this T) and this with C on T.id=C.id &amp;amp; T.x=C.x, which results in T.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second&amp;nbsp;&lt;SPAN&gt;PROC SQL step first joins B and C on B.id=C.id to&amp;nbsp;the intermediate result "one obs. with id=1, x=1, y=1" (call this V) and then joins A with V on A.id=V.id &amp;amp; A.x=V.x, which results in a single observation with&amp;nbsp;id=1, x=&lt;SPAN&gt;2&lt;/SPAN&gt;&lt;SPAN&gt;, y=&lt;STRONG&gt;. (missing)&lt;/STRONG&gt;, because the keys do not match.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;Other examples show that even if both steps create the same observations, the results can differ in the order of observations and in the order of variables.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Mar 2016 10:40:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sequence-of-multiple-left-join/m-p/254820#M57000</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2016-03-06T10:40:48Z</dc:date>
    </item>
  </channel>
</rss>

