<?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: Key for several tables in Proc SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394411#M95032</link>
    <description>&lt;P&gt;I have to comment my question as I think that mislead you in someway.&lt;/P&gt;&lt;P&gt;I have the following tables:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="6.jpg" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/14936i79812F88EC98A53A/image-size/large?v=v2&amp;amp;px=999" role="button" title="6.jpg" alt="6.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I think that the optimal code is as mentioned here - &lt;A href="https://communities.sas.com/t5/SAS-Data-Management/PROC-SQL-Joins-on-3-Tables/td-p/196808" target="_blank"&gt;https://communities.sas.com/t5/SAS-Data-Management/PROC-SQL-Joins-on-3-Tables/td-p/196808&lt;/A&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql
  create table abc as
  select X
  from table1
  left join table2
  on table1.X = table2.X
  left join table3
  on table1.X = table3.X;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The question is how to eliminate columns C and D.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I understand that the solution was metioned above - to use just simple&lt;STRONG&gt; 'select...from'&lt;/STRONG&gt; statement with the following '&lt;STRONG&gt;where':&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;table1.x=table2.x and table1.x=table2.x and table1.x=table3.x&lt;/STRONG&gt;. But would it be possible to use join and eliminate the appropriate columns C and D as in real task the number of tables is quite significant as well as the number of columns to be selected?&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 09 Sep 2017 05:56:15 GMT</pubDate>
    <dc:creator>DmytroYermak</dc:creator>
    <dc:date>2017-09-09T05:56:15Z</dc:date>
    <item>
      <title>Key for several tables in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394371#M95018</link>
      <description>&lt;P&gt;Could you please remind how to join several tables&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
      select key.x1, bb.x1, cc.x2, dd.x3, ee.x4&lt;BR /&gt;      from x1,x2,x3,x4&lt;BR /&gt;      where &lt;EM&gt;key.x1=key.x2=key.x3=key.x4&lt;/EM&gt;&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;What is the correct statement: &lt;EM&gt;key.x1=key.x2=key.x3=key.x4 ?&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Sep 2017 22:50:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394371#M95018</guid>
      <dc:creator>DmytroYermak</dc:creator>
      <dc:date>2017-09-08T22:50:03Z</dc:date>
    </item>
    <item>
      <title>Re: Key for several tables in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394384#M95022</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/58513"&gt;@DmytroYermak&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;You need to refer to variables using &amp;lt;table name|table alias&amp;gt;.&amp;lt;variable name&amp;gt; so it should be x1.key and not key.x1&lt;/P&gt;
&lt;P&gt;Assuming you want an inner join you need an AND between the conditions so something like:&lt;/P&gt;
&lt;P&gt;x1.key=x2.key and x1.key=x3.key and x1.key=x4.key and x2.key=x3.key and x2.key=x4.key and x3.key=x4.key&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2017 02:24:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394384#M95022</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-09-09T02:24:08Z</dc:date>
    </item>
    <item>
      <title>Re: Key for several tables in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394390#M95025</link>
      <description>&lt;P&gt;You can find the solution for similar post at&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Data-Management/PROC-SQL-Joins-on-3-Tables/td-p/196808" target="_blank"&gt;https://communities.sas.com/t5/SAS-Data-Management/PROC-SQL-Joins-on-3-Tables/td-p/196808&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2017 02:20:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394390#M95025</guid>
      <dc:creator>MINX</dc:creator>
      <dc:date>2017-09-09T02:20:23Z</dc:date>
    </item>
    <item>
      <title>Re: Key for several tables in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394393#M95026</link>
      <description>Here's a link to a SAS SQL tutorial:&lt;BR /&gt;&lt;A href="https://onlinecourses.science.psu.edu/stat482/node/39" target="_blank"&gt;https://onlinecourses.science.psu.edu/stat482/node/39&lt;/A&gt;</description>
      <pubDate>Sat, 09 Sep 2017 03:03:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394393#M95026</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-09T03:03:15Z</dc:date>
    </item>
    <item>
      <title>Re: Key for several tables in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394403#M95028</link>
      <description>Thank you, Patrick. I actually thought about this solution but wanted to find anything shorter. That is, actually, the case.</description>
      <pubDate>Sat, 09 Sep 2017 03:41:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394403#M95028</guid>
      <dc:creator>DmytroYermak</dc:creator>
      <dc:date>2017-09-09T03:41:29Z</dc:date>
    </item>
    <item>
      <title>Re: Key for several tables in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394408#M95031</link>
      <description>&lt;P&gt;Sometimes there is a way to make a SAS/SQL join without having to name the variables. If the keys in your tables are the only column names your tables have in common, you can request natural joins.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;proc sql;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;select * &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;from x1 natural join x2 natural join x3 natural join x4;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The joins will be performed on all shared column names.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2017 04:48:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394408#M95031</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-09-09T04:48:24Z</dc:date>
    </item>
    <item>
      <title>Re: Key for several tables in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394411#M95032</link>
      <description>&lt;P&gt;I have to comment my question as I think that mislead you in someway.&lt;/P&gt;&lt;P&gt;I have the following tables:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="6.jpg" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/14936i79812F88EC98A53A/image-size/large?v=v2&amp;amp;px=999" role="button" title="6.jpg" alt="6.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I think that the optimal code is as mentioned here - &lt;A href="https://communities.sas.com/t5/SAS-Data-Management/PROC-SQL-Joins-on-3-Tables/td-p/196808" target="_blank"&gt;https://communities.sas.com/t5/SAS-Data-Management/PROC-SQL-Joins-on-3-Tables/td-p/196808&lt;/A&gt;:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql
  create table abc as
  select X
  from table1
  left join table2
  on table1.X = table2.X
  left join table3
  on table1.X = table3.X;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The question is how to eliminate columns C and D.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I understand that the solution was metioned above - to use just simple&lt;STRONG&gt; 'select...from'&lt;/STRONG&gt; statement with the following '&lt;STRONG&gt;where':&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;table1.x=table2.x and table1.x=table2.x and table1.x=table3.x&lt;/STRONG&gt;. But would it be possible to use join and eliminate the appropriate columns C and D as in real task the number of tables is quite significant as well as the number of columns to be selected?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2017 05:56:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394411#M95032</guid>
      <dc:creator>DmytroYermak</dc:creator>
      <dc:date>2017-09-09T05:56:15Z</dc:date>
    </item>
    <item>
      <title>Re: Key for several tables in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394412#M95033</link>
      <description>You are right, it is my mistake, definitely xn.key=..</description>
      <pubDate>Sat, 09 Sep 2017 05:20:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394412#M95033</guid>
      <dc:creator>DmytroYermak</dc:creator>
      <dc:date>2017-09-09T05:20:19Z</dc:date>
    </item>
    <item>
      <title>Re: Key for several tables in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394419#M95035</link>
      <description>&lt;P&gt;select table1.x, table2.b, table3.d&lt;/P&gt;
&lt;P&gt;from ...&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2017 06:12:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394419#M95035</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-09-09T06:12:03Z</dc:date>
    </item>
    <item>
      <title>Re: Key for several tables in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394423#M95039</link>
      <description>Could you please write the 'where' statement as well?</description>
      <pubDate>Sat, 09 Sep 2017 07:45:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394423#M95039</guid>
      <dc:creator>DmytroYermak</dc:creator>
      <dc:date>2017-09-09T07:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: Key for several tables in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394429#M95042</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/58513"&gt;@DmytroYermak&lt;/a&gt;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/58513"&gt;@DmytroYermak&lt;/a&gt; wrote:&lt;BR /&gt;Could you please write the 'where' statement as well?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The rest of the SQL code you've posted was fine for the example you've posted. Just combine the SELECT bit as posted by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;with the other parts you've posted already.&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2017 11:55:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394429#M95042</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-09-09T11:55:18Z</dc:date>
    </item>
    <item>
      <title>Re: Key for several tables in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394444#M95048</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/58513"&gt;@DmytroYermak&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I have to comment my question as I think that mislead you in someway.&lt;/P&gt;
&lt;P&gt;I have the following tables:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="6.jpg" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/14936i79812F88EC98A53A/image-size/large?v=v2&amp;amp;px=999" role="button" title="6.jpg" alt="6.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I think that the optimal code is as mentioned here - &lt;A href="https://communities.sas.com/t5/SAS-Data-Management/PROC-SQL-Joins-on-3-Tables/td-p/196808" target="_blank"&gt;https://communities.sas.com/t5/SAS-Data-Management/PROC-SQL-Joins-on-3-Tables/td-p/196808&lt;/A&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql
  create table abc as
  select X
  from table1
  left join table2
  on table1.X = table2.X
  left join table3
  on table1.X = table3.X;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The question is how to eliminate columns C and D.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I understand that the solution was metioned above - to use just simple&lt;STRONG&gt; 'select...from'&lt;/STRONG&gt; statement with the following '&lt;STRONG&gt;where':&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;table1.x=table2.x and table1.x=table2.x and table1.x=table3.x&lt;/STRONG&gt;. But would it be possible to use join and eliminate the appropriate columns C and D as in real task the number of tables is quite significant as well as the number of columns to be selected?&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Sometimes it is easier to take advantage of SAS dataset options. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example if you want everything but C and D then you drop them on the way out.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
create table abc(drop=C D) as
  select *
  from table1
  natural left join table2
  natural left join table3
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or drop them on the way in.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
create table abc as
  select *
  from table1
  natural left join table2(drop=C)
  natural left join table3(drop=D)
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Sep 2017 14:16:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394444#M95048</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-09-09T14:16:36Z</dc:date>
    </item>
    <item>
      <title>Re: Key for several tables in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394466#M95060</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;, I also thought of this solution, but natural left joins are somewhat counter intuitive. There seems to be no way to force&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;select x, b, d&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;from t1 natural left join t2 natural left join t3;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;to be like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;select t1.x, b, d&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;from t1 left join t2 on t1.x=t2.x left join t3 on t1.x=t3.x;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;it keeps being interpreted as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;select t1.x, b, d&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;from t1 left join t2 on t1.x=t2.x left join t3 on &lt;FONT color="#ff6600"&gt;t2&lt;/FONT&gt;.x=t3.x;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;even with parentheses, which means that &lt;STRONG&gt;t1&lt;/STRONG&gt; cannot be treated as the key reference for both joins.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way around this with natural joins is&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; t1;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;infile&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; datalines &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;missover&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; x a$;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;P&gt;2 a&lt;/P&gt;
&lt;P&gt;3 a&lt;/P&gt;
&lt;P&gt;4 a&lt;/P&gt;
&lt;P&gt;5 a&lt;/P&gt;
&lt;P&gt;6&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; t2;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;infile&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; datalines &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;missover&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; x b$ c$;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;1 b c&lt;/P&gt;
&lt;P&gt;3 b c&lt;/P&gt;
&lt;P&gt;5 b c&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; t3;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;infile&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; datalines &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;missover&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; x d$ e$;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;2 d e&lt;/P&gt;
&lt;P&gt;4 d e&lt;/P&gt;
&lt;P&gt;6 d e&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; x, b, d&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;from&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;( &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; * &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; t1 natural &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;left&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;join&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; t2 )&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;natural &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;join&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;( &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; * &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; t1 natural &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;left&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;join&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; t3 )&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2017 19:12:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394466#M95060</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-09-09T19:12:05Z</dc:date>
    </item>
    <item>
      <title>Re: Key for several tables in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394467#M95061</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Good to know about how SAS performs the NATURAL joins.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case you can nest&amp;nbsp;the queries to get SAS to do the same thing as it would in a normal merge.&lt;/P&gt;
&lt;P&gt;Note that if you want the SQL process to put the variables in the same order as a normal merge would then you need to reference the tables in SQL query in the reverse order.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  merge t1(in=in1) t2 t3;
  by x ;
  if in1;
run;

proc sql ;
  create table test2 as
  select * 
  from (select * from t3 natural full join t2 ) c1
  natural right join t1
  ;
quit;
proc print data=want;
run;
proc print data=test2;
run;
proc compare data=want compare=test2 ; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    x    a    b    c    d    e

 1     1         b    c
 2     2    a              d    e
 3     3    a    b    c
 4     4    a              d    e
 5     5    a    b    c
 6     6                   d    e


Obs    x    a    b    c    d    e

 1     1         b    c
 2     2    a              d    e
 3     3    a    b    c
 4     4    a              d    e
 5     5    a    b    c
 6     6                   d    e



The COMPARE Procedure
Comparison of WORK.WANT with WORK.TEST2
(Method=EXACT)

NOTE: No unequal values were found. All values compared are exactly equal.
&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Sep 2017 19:30:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394467#M95061</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-09-09T19:30:13Z</dc:date>
    </item>
    <item>
      <title>Re: Key for several tables in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394470#M95064</link>
      <description>&lt;P&gt;Thank you both for the detailed analysis. I wanted to put here my not fancy code but am seeing that have to investigatate yours that is working ).&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2017 19:47:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394470#M95064</guid>
      <dc:creator>DmytroYermak</dc:creator>
      <dc:date>2017-09-09T19:47:47Z</dc:date>
    </item>
    <item>
      <title>Re: Key for several tables in Proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394520#M95083</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/58513"&gt;@DmytroYermak&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thank you both for the detailed analysis. I wanted to put here my not fancy code but am seeing that have to investigatate yours that is working ).&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;As long as you are not trying to do many to many merge then it is much easier to code multiple dataset merges using normal SAS code than to trying to force into SQL syntax.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example you could merge 20 datasets. &amp;nbsp;List the variables you want to drop or keep. And best of all no ***** commas needed.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  merge t1(in=in1) t2-t20 ;
  by x ;
  if in1;
  drop C D ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 10 Sep 2017 17:17:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Key-for-several-tables-in-Proc-SQL/m-p/394520#M95083</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-09-10T17:17:41Z</dc:date>
    </item>
  </channel>
</rss>

