<?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 Merge two tables using proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Merge-two-tables-using-proc-sql/m-p/474312#M121847</link>
    <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two tables to merge and whilst I know how to merge using both SAS data step and Proc Sql, I prefer to use proc sql however the problem I am facing is how to &amp;nbsp;keep all columns for the first table and only&amp;nbsp;specific columns for the second table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;It should be&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc Sql;&lt;/P&gt;&lt;P&gt;Create table Accounts as&lt;/P&gt;&lt;P&gt;Select * from table 1&lt;/P&gt;&lt;P&gt;Select a, b,c&amp;nbsp; from table 2&lt;/P&gt;&lt;P&gt;left join&amp;nbsp; table 2 on ( table1.a=table2.a);&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I truly appreciate your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Mags&lt;/P&gt;</description>
    <pubDate>Fri, 29 Jun 2018 00:28:27 GMT</pubDate>
    <dc:creator>Timbim</dc:creator>
    <dc:date>2018-06-29T00:28:27Z</dc:date>
    <item>
      <title>Merge two tables using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-two-tables-using-proc-sql/m-p/474312#M121847</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two tables to merge and whilst I know how to merge using both SAS data step and Proc Sql, I prefer to use proc sql however the problem I am facing is how to &amp;nbsp;keep all columns for the first table and only&amp;nbsp;specific columns for the second table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;It should be&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc Sql;&lt;/P&gt;&lt;P&gt;Create table Accounts as&lt;/P&gt;&lt;P&gt;Select * from table 1&lt;/P&gt;&lt;P&gt;Select a, b,c&amp;nbsp; from table 2&lt;/P&gt;&lt;P&gt;left join&amp;nbsp; table 2 on ( table1.a=table2.a);&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I truly appreciate your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;Mags&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jun 2018 00:28:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-two-tables-using-proc-sql/m-p/474312#M121847</guid>
      <dc:creator>Timbim</dc:creator>
      <dc:date>2018-06-29T00:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: Merge two tables using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Merge-two-tables-using-proc-sql/m-p/474327#M121852</link>
      <description>&lt;P&gt;Please post your code using a code box. In the Rich Text Editor it's the 6/7th icons (notebook or i). This makes it easier to copy/paste, doesn't introduce emoticons and its more legible.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You use * as a wildcard to reference all columns. To reference all columns in a specific table list it as either 'TableName.*' or 'Alias.*'.&lt;/P&gt;
&lt;P&gt;Typically I use a table alias so I don't have to type out the full name.&amp;nbsp; t1/t2/tN is common. You can also use this convention on the join conditions and elsewhere in the query. See example below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Proc Sql;

Create table Accounts as
Select t1.*, t2.ID, t2.Age
from table1 as t1 /*alias is t1 for table1*/
left join  table2 as t2 /*alias is t2 for table2*/
on t1.a=t2.a;

quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138573"&gt;@Timbim&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have two tables to merge and whilst I know how to merge using both SAS data step and Proc Sql, I prefer to use proc sql however the problem I am facing is how to &amp;nbsp;keep all columns for the first table and only&amp;nbsp;specific columns for the second table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;It should be&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc Sql;&lt;/P&gt;
&lt;P&gt;Create table Accounts as&lt;/P&gt;
&lt;P&gt;Select * from table 1&lt;/P&gt;
&lt;P&gt;Select a, b,c&amp;nbsp; from table 2&lt;/P&gt;
&lt;P&gt;left join&amp;nbsp; table 2 on ( table1.a=table2.a);&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I truly appreciate your help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards,&lt;/P&gt;
&lt;P&gt;Mags&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jun 2018 02:00:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Merge-two-tables-using-proc-sql/m-p/474327#M121852</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-29T02:00:52Z</dc:date>
    </item>
  </channel>
</rss>

