<?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 avoid warning msg in proc sql when merging 2 tables in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/avoid-warning-msg-in-proc-sql-when-merging-2-tables/m-p/170569#M44082</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello:&lt;/P&gt;&lt;P&gt;&amp;nbsp; I am trying to merge 2 tables in sql by two variables subject and centre. Here is what I did&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt; create table master_table as&lt;/P&gt;&lt;P&gt; select d1.*, d2.* from d1 and d2 where d1.subject = d2.subject and d1.centre = d2.centre;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SAS prints a warning message in the log saying that "subject" and "centre" already exist in master_table. I understand the message is due to the common variable names in both datasets. One way to avoid the warning msg is to explicitly spell out all variable names in d1. However, this is really tedious especially when I have hundreds of variables. Is there anyway to say "select all columns other than subject and centre from d1" so the warning is suppressed?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Peter&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 11 Feb 2014 16:28:58 GMT</pubDate>
    <dc:creator>Peter_Y</dc:creator>
    <dc:date>2014-02-11T16:28:58Z</dc:date>
    <item>
      <title>avoid warning msg in proc sql when merging 2 tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/avoid-warning-msg-in-proc-sql-when-merging-2-tables/m-p/170569#M44082</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello:&lt;/P&gt;&lt;P&gt;&amp;nbsp; I am trying to merge 2 tables in sql by two variables subject and centre. Here is what I did&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt; create table master_table as&lt;/P&gt;&lt;P&gt; select d1.*, d2.* from d1 and d2 where d1.subject = d2.subject and d1.centre = d2.centre;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SAS prints a warning message in the log saying that "subject" and "centre" already exist in master_table. I understand the message is due to the common variable names in both datasets. One way to avoid the warning msg is to explicitly spell out all variable names in d1. However, this is really tedious especially when I have hundreds of variables. Is there anyway to say "select all columns other than subject and centre from d1" so the warning is suppressed?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Peter&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Feb 2014 16:28:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/avoid-warning-msg-in-proc-sql-when-merging-2-tables/m-p/170569#M44082</guid>
      <dc:creator>Peter_Y</dc:creator>
      <dc:date>2014-02-11T16:28:58Z</dc:date>
    </item>
    <item>
      <title>Re: avoid warning msg in proc sql when merging 2 tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/avoid-warning-msg-in-proc-sql-when-merging-2-tables/m-p/170570#M44083</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Before running the code create a macro variable with the column names you want, e.g. (untested):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;proc sql noprint;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; select name into :d1columns separated by ','&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; from dictionary.columns&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; where libname='WORK'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; and memname='D1'&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; and upcase(name) not in ('&lt;SPAN style="background-color: #ffffff;"&gt;SUBJECT&lt;/SPAN&gt;','CENTRE')&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then you can use the macro variable in your code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;create table master_table as&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;select &lt;STRONG&gt;&amp;amp;d1columns&lt;/STRONG&gt;, d2.* from d1 and d2 where d1.subject = d2.subject and d1.centre = d2.centre;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Amir.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Amir Malik - fixed memname&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Feb 2014 17:56:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/avoid-warning-msg-in-proc-sql-when-merging-2-tables/m-p/170570#M44083</guid>
      <dc:creator>Amir</dc:creator>
      <dc:date>2014-02-11T17:56:16Z</dc:date>
    </item>
    <item>
      <title>Re: avoid warning msg in proc sql when merging 2 tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/avoid-warning-msg-in-proc-sql-when-merging-2-tables/m-p/170571#M44084</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can try the feedback option to get all your columns listed, rather than having to type them out. &lt;/P&gt;&lt;P&gt;The select statement will be expanded in the log. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;496&amp;nbsp; proc sql feedback;&lt;/P&gt;&lt;P&gt;497&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table want as&lt;/P&gt;&lt;P&gt;498&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select *&lt;/P&gt;&lt;P&gt;499&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from sashelp.class as A;&lt;/P&gt;&lt;P&gt;NOTE: Statement transforms to:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select A.Name, A.Sex, A.Age, A.Height, A.Weight&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from SASHELP.CLASS A;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;NOTE: Table WORK.WANT created, with 19 rows and 5 columns.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;500&amp;nbsp; quit;&lt;/P&gt;&lt;P&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.01 seconds&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cpu time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.01 seconds&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I also think you should modify your code to read as follows, as this prevents a full Cartesian join. I'd also explicitly specify my join type (inner, left, right, outer)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt; create table master_table as&lt;/P&gt;&lt;P&gt; select d1.*, d2.* &lt;/P&gt;&lt;P&gt;&amp;nbsp; from d1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; join d2 &lt;/P&gt;&lt;P&gt;on d1.subject = d2.subject and d1.centre = d2.centre;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Feb 2014 18:07:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/avoid-warning-msg-in-proc-sql-when-merging-2-tables/m-p/170571#M44084</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-02-11T18:07:38Z</dc:date>
    </item>
    <item>
      <title>Re: avoid warning msg in proc sql when merging 2 tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/avoid-warning-msg-in-proc-sql-when-merging-2-tables/m-p/170572#M44085</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can also do a rename (and optionally drop the duplicate columns) to avoid the message:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table master_table (drop = subject2 centre2)&amp;nbsp; as&lt;/P&gt;&lt;P&gt;select *&lt;/P&gt;&lt;P&gt;from d1, d2 (rename = (subject = subject2 centre = centre2)) &lt;/P&gt;&lt;P&gt;where d1.subject = d2.subject2 and d1.centre = d2.centre2;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Feb 2014 19:00:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/avoid-warning-msg-in-proc-sql-when-merging-2-tables/m-p/170572#M44085</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2014-02-11T19:00:35Z</dc:date>
    </item>
    <item>
      <title>Re: avoid warning msg in proc sql when merging 2 tables</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/avoid-warning-msg-in-proc-sql-when-merging-2-tables/m-p/170573#M44086</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could try using NATURAL JOIN.&amp;nbsp;&amp;nbsp; It will have issues if there are other common variables, but then you would have received warnings about those with your current code.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;proc sql;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;create table master_table as&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; select d1.*, d2.*&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; from d1 natural join d2 &lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Feb 2014 19:20:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/avoid-warning-msg-in-proc-sql-when-merging-2-tables/m-p/170573#M44086</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-02-11T19:20:30Z</dc:date>
    </item>
  </channel>
</rss>

