<?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: chain of SQL joinings in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/chain-of-SQL-joinings/m-p/323984#M271265</link>
    <description>&lt;P&gt;Because the code doesn't select anything from c.table the last part isn't changing anything, but you could do this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table combined as&lt;BR /&gt;select a.*,b.balance,c.dwo_status&lt;BR /&gt;from one a left join&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; two b&lt;BR /&gt;on a.id=b.id&lt;BR /&gt;left join three_dwo c&lt;BR /&gt;on a.id=c.id;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second join links table C to the table that was created between A and B.&amp;nbsp; Because they are both left joins table B and C both left join to table A.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which would pull in the field from three_dwo&lt;/P&gt;</description>
    <pubDate>Wed, 11 Jan 2017 16:09:40 GMT</pubDate>
    <dc:creator>Steelers_In_DC</dc:creator>
    <dc:date>2017-01-11T16:09:40Z</dc:date>
    <item>
      <title>chain of SQL joinings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/chain-of-SQL-joinings/m-p/323972#M271264</link>
      <description>&lt;P&gt;/*Hi SAS Forum,*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*My co-worker has done a chain of sql left joins like below. Could you&lt;/P&gt;&lt;P&gt;help me to understand it*/&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; one;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; id limit;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;cards&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;111 15000&lt;/P&gt;&lt;P&gt;222 25000&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; two;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; id balance;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;cards&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;111 500&lt;/P&gt;&lt;P&gt;222 300&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; three_dwo;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; id dwo_status $ &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;5&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;7&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;cards&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;111 dwo&lt;/P&gt;&lt;P&gt;222 no&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;/*Below is the clumsy SQL joining*/&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;/*I can understand below piece in which we associate "balance" field to our "one" table*/&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;create&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;table&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; combined &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt; &lt;FONT color="#008080" face="Courier New" size="3"&gt;a.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;*&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;,b.balance&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; one &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; a &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;left&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;join&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; two &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; b&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;on&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; a.id=b.id&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Below is the step I cannot understand. To which table we do the left joining of "three_dwo" table?*/&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;left&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;join&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; three_dwo &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; c&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;on&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; a.id=c.id;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;&amp;nbsp;/*Thanks, Mirisa*/&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jan 2017 15:50:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/chain-of-SQL-joinings/m-p/323972#M271264</guid>
      <dc:creator>dunga</dc:creator>
      <dc:date>2017-01-11T15:50:44Z</dc:date>
    </item>
    <item>
      <title>Re: chain of SQL joinings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/chain-of-SQL-joinings/m-p/323984#M271265</link>
      <description>&lt;P&gt;Because the code doesn't select anything from c.table the last part isn't changing anything, but you could do this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;create table combined as&lt;BR /&gt;select a.*,b.balance,c.dwo_status&lt;BR /&gt;from one a left join&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; two b&lt;BR /&gt;on a.id=b.id&lt;BR /&gt;left join three_dwo c&lt;BR /&gt;on a.id=c.id;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second join links table C to the table that was created between A and B.&amp;nbsp; Because they are both left joins table B and C both left join to table A.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which would pull in the field from three_dwo&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jan 2017 16:09:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/chain-of-SQL-joinings/m-p/323984#M271265</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2017-01-11T16:09:40Z</dc:date>
    </item>
    <item>
      <title>Re: chain of SQL joinings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/chain-of-SQL-joinings/m-p/324061#M271266</link>
      <description>&lt;P&gt;&lt;FONT color="#0000ff"&gt;Hi Steelers,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff"&gt;Thank you very much.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff"&gt;I still have a few questions which are embedded in red color in your response below.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table combined as&lt;BR /&gt;select a.*,b.balance,c.dwo_status&lt;BR /&gt;from one a left join&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; two b&lt;BR /&gt;on a.id=b.id&lt;BR /&gt;left join three_dwo c&amp;nbsp; &lt;FONT color="#ff0000"&gt;/*this is the second join*/&lt;/FONT&gt;&lt;BR /&gt;on a.id=c.id;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The second join links table C to the table that was created between A and B &lt;FONT color="#ff0000"&gt;(the table created between A and B is "combined". So, this means second join links table C to table "combined". Am I right?&amp;nbsp;If this is right, then the resultant table due to the second join is&amp;nbsp;what? Is the resultant table is again "combined".?&amp;nbsp;)&lt;/FONT&gt;.&amp;nbsp; Because they are both left joins table B and C both left join to table A.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Which would pull in the field from three_dwo&lt;/P&gt;</description>
      <pubDate>Wed, 11 Jan 2017 21:30:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/chain-of-SQL-joinings/m-p/324061#M271266</guid>
      <dc:creator>dunga</dc:creator>
      <dc:date>2017-01-11T21:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: chain of SQL joinings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/chain-of-SQL-joinings/m-p/324151#M271267</link>
      <description>&lt;P&gt;It's a bit hard to read but if you're really interested how SAS processes the query then options _method and _tree write quite a bit of information to the log.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Running below code will illustrate what you can get in the SAS Log. If you really want to understand how to interprete the log messages then Google for some of the very informative white papers which give you a deep dive into this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
  ona=1;
  do id= 1 to 5;
    output;
  end;
run;

data two;
  balance=10;
  do id= 1 to 4, 6, 7;
    output;
  end;
run;

data three_dwo;
  dwo_status=100;
  do id= 1 to 3, 7,8;
    output;
  end;
run;

  
proc sql _method _tree feedback;
  create table combined as
    select a.*,b.balance,c.dwo_status
      from one a left join
        two b
        on a.id=b.id
      left join three_dwo c  /*this is the second join*/
  on a.id=c.id;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2017 15:39:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/chain-of-SQL-joinings/m-p/324151#M271267</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-01-12T15:39:00Z</dc:date>
    </item>
    <item>
      <title>Re: chain of SQL joinings</title>
      <link>https://communities.sas.com/t5/SAS-Programming/chain-of-SQL-joinings/m-p/324250#M271268</link>
      <description>&lt;P&gt;Hi Patrick,&lt;/P&gt;&lt;P&gt;Thank you very much.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mirisa&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2017 14:24:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/chain-of-SQL-joinings/m-p/324250#M271268</guid>
      <dc:creator>dunga</dc:creator>
      <dc:date>2017-01-12T14:24:11Z</dc:date>
    </item>
  </channel>
</rss>

