<?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: sql tables and ambiguous reference error message in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/sql-tables-and-ambiguous-reference-error-message/m-p/86140#M24587</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That query, written as it is, should work, unless new_ID doesn't have the same type or size in both tables, or have_1 or have_2 are views instead of tables, in which case the root of the problem could be inside one of those views.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 17 Apr 2012 15:05:43 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2012-04-17T15:05:43Z</dc:date>
    <item>
      <title>sql tables and ambiguous reference error message</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sql-tables-and-ambiguous-reference-error-message/m-p/86138#M24585</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Sas users,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you please recommend a way to fix the belwo code?&amp;nbsp; I'm currently receiving the error message; "Ambiguous reference, column new_ID is in more than one table."&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In a nutshell I would like to create a new dataset "want" based on dataset "have_1" except I don't want to include in "want" any that are also in "have_2".&amp;nbsp; The variable in common is "new_ID".&amp;nbsp; There are duplicate "new_IDs" in "have_1" which may be causing the error message.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table want as&lt;/P&gt;&lt;P&gt;select new_ID from have_1&lt;/P&gt;&lt;P&gt;except&lt;/P&gt;&lt;P&gt;select new_ID from have_2;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Apr 2012 14:38:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sql-tables-and-ambiguous-reference-error-message/m-p/86138#M24585</guid>
      <dc:creator>sophia_SAS</dc:creator>
      <dc:date>2012-04-17T14:38:32Z</dc:date>
    </item>
    <item>
      <title>Re: sql tables and ambiguous reference error message</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sql-tables-and-ambiguous-reference-error-message/m-p/86139#M24586</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;data one;&lt;/P&gt;&lt;P&gt;input no;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data two;&lt;/P&gt;&lt;P&gt;input no;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;4&lt;/P&gt;&lt;P&gt;5&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;merge one(in=a) two(in=b);&lt;/P&gt;&lt;P&gt;by no;&lt;/P&gt;&lt;P&gt;if a ne b;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Shiva&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Apr 2012 14:59:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sql-tables-and-ambiguous-reference-error-message/m-p/86139#M24586</guid>
      <dc:creator>shivas</dc:creator>
      <dc:date>2012-04-17T14:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: sql tables and ambiguous reference error message</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sql-tables-and-ambiguous-reference-error-message/m-p/86140#M24587</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That query, written as it is, should work, unless new_ID doesn't have the same type or size in both tables, or have_1 or have_2 are views instead of tables, in which case the root of the problem could be inside one of those views.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Apr 2012 15:05:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sql-tables-and-ambiguous-reference-error-message/m-p/86140#M24587</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2012-04-17T15:05:43Z</dc:date>
    </item>
    <item>
      <title>Re: sql tables and ambiguous reference error message</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sql-tables-and-ambiguous-reference-error-message/m-p/86141#M24588</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try:&lt;/P&gt;&lt;P&gt;select distinct new_id from have_1&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Apr 2012 15:05:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sql-tables-and-ambiguous-reference-error-message/m-p/86141#M24588</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2012-04-17T15:05:46Z</dc:date>
    </item>
    <item>
      <title>Re: sql tables and ambiguous reference error message</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sql-tables-and-ambiguous-reference-error-message/m-p/86142#M24589</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Working fine for me even with duplicates.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have_1;&lt;BR /&gt;input new_id name $1. ;&lt;BR /&gt;cards;&lt;BR /&gt;1 a&lt;BR /&gt;2 b&lt;BR /&gt;3 c&lt;BR /&gt;4 d&lt;BR /&gt;1 a&lt;BR /&gt;1 b&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data have_2;&lt;BR /&gt;input new_id;&lt;BR /&gt;cards;&lt;BR /&gt;5&lt;BR /&gt;6&lt;BR /&gt;7&lt;BR /&gt;8&lt;BR /&gt;9&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select new_ID from have_1&lt;BR /&gt;except&lt;BR /&gt;select new_ID from have_2;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Log:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1455&amp;nbsp; data have_1;&lt;BR /&gt;1456&amp;nbsp; input new_id name $1. ;&lt;BR /&gt;1457&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;NOTE: The data set WORK.HAVE_1 has 6 observations and 2 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&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.00 seconds&lt;BR /&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.00 seconds&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;1464&amp;nbsp; run;&lt;BR /&gt;1465&lt;BR /&gt;1466&amp;nbsp; data have_2;&lt;BR /&gt;1467&amp;nbsp; input new_id;&lt;BR /&gt;1468&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;NOTE: The data set WORK.HAVE_2 has 5 observations and 1 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&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;BR /&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.00 seconds&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;1474&amp;nbsp; ;&lt;BR /&gt;1475&amp;nbsp; run;&lt;BR /&gt;1476&lt;BR /&gt;1477&amp;nbsp; proc sql;&lt;BR /&gt;1478&amp;nbsp; create table want as&lt;BR /&gt;1479&amp;nbsp; select new_ID from have_1&lt;BR /&gt;1480&amp;nbsp; except&lt;BR /&gt;1481&amp;nbsp; select new_ID from have_2;&lt;BR /&gt;NOTE: Table WORK.WANT created, with 4 rows and 1 columns.&lt;/P&gt;&lt;P&gt;1482&amp;nbsp; quit;&lt;BR /&gt;NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&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;BR /&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.00 seconds&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 17 Apr 2012 15:07:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sql-tables-and-ambiguous-reference-error-message/m-p/86142#M24589</guid>
      <dc:creator>Hima</dc:creator>
      <dc:date>2012-04-17T15:07:29Z</dc:date>
    </item>
    <item>
      <title>Re: sql tables and ambiguous reference error message</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/sql-tables-and-ambiguous-reference-error-message/m-p/530416#M73717</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are two methods:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;METHOD 1: Using a where clause in both directions combined by a union all.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Method 1: &lt;BR /&gt;PROC SQL;
CREATE TABLE WANT AS 
SELECT UNIQUE NEW_ID FROM HAVE_1
WHERE NEW_ID NOT IN (SELECT UNIQUE NEW_ID FROM HAVE_2)&lt;BR /&gt;UNION ALL &lt;BR /&gt;SELECT UNIQUE NEW_ID FROM HAVE_2&lt;BR /&gt;WHERE NEW_ID NOT IN (SELECT UNIQUE NEW_ID FROM HAVE_2)
;QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Method 2:&amp;nbsp;&lt;/P&gt;&lt;P&gt;Leveraging subqueries to create a union all NEW_ID's. Both tables have only 1 column, so it isn't ambiguous. The outermost query deduplicates.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;METHOD 2: 
PROC SQL;
CREATE TABLE WANT AS 
SELECT UNIQUE *
FROM (SELECT * FROM (SELECT UNIQUE NEW_ID FROM HAVE_1)
                 UNION ALL
             SELECT * FROM (SELECT UNIQUE NEW_ID FROM HAVE_1)
            )
;QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 27 Jan 2019 04:36:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/sql-tables-and-ambiguous-reference-error-message/m-p/530416#M73717</guid>
      <dc:creator>rsanchez87</dc:creator>
      <dc:date>2019-01-27T04:36:05Z</dc:date>
    </item>
  </channel>
</rss>

