<?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: PROC SQL ERROR Ambigous Reference in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-ERROR-Ambigous-Reference/m-p/545295#M8010</link>
    <description>Thank you for the feedback. This was the perfect solution. Jane</description>
    <pubDate>Fri, 22 Mar 2019 16:50:48 GMT</pubDate>
    <dc:creator>jawhitmire</dc:creator>
    <dc:date>2019-03-22T16:50:48Z</dc:date>
    <item>
      <title>PROC SQL ERROR Ambigous Reference</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-ERROR-Ambigous-Reference/m-p/545264#M7999</link>
      <description>&lt;P&gt;SAS Version 9.4 /&amp;nbsp;Omit SAS/STATS or SAS/IML&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Good day -&lt;/P&gt;&lt;P&gt;The message in the log reads:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: Ambiguous reference, column bird is in more than one table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the source code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.g_calc;
	input bird $ gmass;
	cards;
	bird1 11
	bird3 33
	bird6 66
	;
run;

data work.h_calc;
	input bird $ hmass;
	cards;
	bird1 1
	bird2 2
	bird3 3
	bird4 4
	bird5 5
	bird6 6
	;
run;

data work.c_calc;
	input bird $ cmass;
	cards;
	bird1 10
	bird2 20
	bird3 30
	bird4 40
	bird5 50
	bird6 60
	;
run;
%let gtotal=110;
%let htotal=21;
%let ctotal=210;

proc sql;
	create table work.equation as
	select distinct bird,
	sum(H.hmass,G.gmass,C.cmass)/(&amp;amp;htotal. + &amp;amp;gtotal. + &amp;amp;ctotal.) as result 
	from work.h_calc as H, work.g_calc as G,work.c_calc as C
	where H.bird=G.bird or G.bird=C.bird or C.bird=H.bird;
quit;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What is the best way to get rid of the error message and successfully compile to get results of the equation which is the sum of the bird masses over sum of totals.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also tried using "select unique bird" on the second line of "proc sql", but the same error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output should be approximately:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;bird&amp;nbsp;&amp;nbsp;result&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;bird1&amp;nbsp; 0.0645&lt;/P&gt;&lt;P&gt;bird2&amp;nbsp; 0.0645&lt;/P&gt;&lt;P&gt;bird3&amp;nbsp; 0.1935&lt;/P&gt;&lt;P&gt;bird4&amp;nbsp; 0.129&lt;/P&gt;&lt;P&gt;bird5&amp;nbsp; 0.16129&lt;/P&gt;&lt;P&gt;bird6&amp;nbsp; 0.38709&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where 22/341=0.0645, 66/341=0.1935, 44/341=0.129, 55/341=0.16129, and 132/341=0.38709&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;&lt;P&gt;Jane&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 16:04:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-ERROR-Ambigous-Reference/m-p/545264#M7999</guid>
      <dc:creator>jawhitmire</dc:creator>
      <dc:date>2019-03-22T16:04:24Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL ERROR Ambigous Reference</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-ERROR-Ambigous-Reference/m-p/545267#M8000</link>
      <description>&lt;P&gt;Reference correctly in your select statement&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select distinct &lt;STRONG&gt;h.bird&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 15:53:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-ERROR-Ambigous-Reference/m-p/545267#M8000</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-22T15:53:20Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL ERROR Ambigous Reference</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-ERROR-Ambigous-Reference/m-p/545269#M8001</link>
      <description>&lt;P&gt;You're matching when the two of the birds on the table agree, regardless if the third agree's. So you could have:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;bird1 bird1 bird3 -&amp;gt; which value do you want to appear in the table?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or, should the OR conditions in your WHERE statement be AND instead?&lt;/P&gt;
&lt;P&gt;I suspect that's actually what you're trying to do.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/248885"&gt;@jawhitmire&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;SAS Version 9.4 /&amp;nbsp;Omit SAS/STATS or SAS/IML&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good day -&lt;/P&gt;
&lt;P&gt;The message in the log reads:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: Ambiguous reference, column bird is in more than one table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the source code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.g_calc;
	input bird $ gmass;
	cards;
	bird1 11
	bird3 33
	bird6 66
	;
run;

data work.h_calc;
	input bird $ hmass;
	cards;
	bird1 1
	bird2 2
	bird3 3
	bird4 4
	bird5 5
	bird6 6
	;
run;

data work.c_calc;
	input bird $ cmass;
	cards;
	bird1 10
	bird2 20
	bird3 30
	bird4 40
	bird5 50
	bird6 60
	;
run;
%let gtotal=110;
%let htotal=21;
%let ctotal=210;

proc sql;
	create table work.equation as
	select distinct bird,
	sum(H.hmass,G.gmass,C.cmass)/(&amp;amp;htotal. + &amp;amp;gtotal. + &amp;amp;ctotal.) as result 
	from work.h_calc as H, work.g_calc as G,work.c_calc as C
	where H.bird=G.bird or G.bird=C.bird or C.bird=H.bird;
quit;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What is the best way to get rid of the error message and successfully compile to get results of the equation which is the sum of the bird masses over sum of totals.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also tried using "select unique bird" on the second line of "proc sql", but the same error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance.&lt;/P&gt;
&lt;P&gt;Jane&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 15:54:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-ERROR-Ambigous-Reference/m-p/545269#M8001</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-03-22T15:54:51Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL ERROR Ambigous Reference</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-ERROR-Ambigous-Reference/m-p/545270#M8002</link>
      <description>&lt;P&gt;What does your desired output look like from your example data? First, you have to reference which table bird should come from, such as C.bird in your select statement.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 15:55:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-ERROR-Ambigous-Reference/m-p/545270#M8002</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-03-22T15:55:33Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL ERROR Ambigous Reference</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-ERROR-Ambigous-Reference/m-p/545271#M8003</link>
      <description>&lt;P&gt;or something like this perhaps&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	select distinct coalescec(h.bird,G.bird,C.bird) as bird&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 15:55:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-ERROR-Ambigous-Reference/m-p/545271#M8003</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-22T15:55:55Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL ERROR Ambigous Reference</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-ERROR-Ambigous-Reference/m-p/545272#M8004</link>
      <description>&lt;PRE&gt;proc sql;
	create table work.equation as
	select distinct &lt;STRONG&gt;bird&lt;/STRONG&gt;,
	sum(H.hmass,G.gmass,C.cmass)/(&amp;amp;htotal. + &amp;amp;gtotal. + &amp;amp;ctotal.) as result 
	from work.h_calc as H, work.g_calc as G,work.c_calc as C
	where &lt;FONT color="#ff0000"&gt;&lt;STRONG&gt;H.bird&lt;/STRONG&gt;&lt;/FONT&gt;=&lt;FONT color="#0000ff"&gt;&lt;STRONG&gt;G.bird&lt;/STRONG&gt; &lt;/FONT&gt;or G.bird=&lt;FONT color="#ff00ff"&gt;&lt;STRONG&gt;C.bird&lt;/STRONG&gt; &lt;/FONT&gt;or C.bird=H.bird;
quit;&lt;/PRE&gt;
&lt;P&gt;So, which of the 3 birds are supposed to provide the distinct &lt;STRONG&gt;bird&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;One of the color highlighted versions should be the selection.&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 15:57:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-ERROR-Ambigous-Reference/m-p/545272#M8004</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-22T15:57:57Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL ERROR Ambigous Reference</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-ERROR-Ambigous-Reference/m-p/545278#M8005</link>
      <description>&lt;P&gt;Thank you for the feedback.&lt;/P&gt;&lt;P&gt;Next, I tried...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table work.equation as
	select distinct h.bird,
	sum(H.hmass,G.gmass,C.cmass)/(&amp;amp;htotal. + &amp;amp;gtotal. + &amp;amp;ctotal.) as result 
	from work.h_calc as H, work.g_calc as G,work.c_calc as C
	where H.bird=G.bird and G.bird=C.bird and C.bird=H.bird;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It runs successfully - thank you.&lt;/P&gt;&lt;P&gt;The problem is that there is only 3 observations in the output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;bird&amp;nbsp; result&lt;/P&gt;&lt;P&gt;bird1&amp;nbsp; 0.06452&lt;/P&gt;&lt;P&gt;bird3 0.19355&lt;/P&gt;&lt;P&gt;bird6 0.38710&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like the calculation performed for all 6 birds - is this possible with "proc sql'?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jane&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 22 Mar 2019 16:15:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-ERROR-Ambigous-Reference/m-p/545278#M8005</guid>
      <dc:creator>jawhitmire</dc:creator>
      <dc:date>2019-03-22T16:15:31Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL ERROR Ambigous Reference</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-ERROR-Ambigous-Reference/m-p/545282#M8006</link>
      <description>bird result&lt;BR /&gt;&lt;BR /&gt;bird1 0.0645&lt;BR /&gt;bird2 0.0645&lt;BR /&gt;bird3 0.1935&lt;BR /&gt;bird4 0.129&lt;BR /&gt;bird5 0.16129&lt;BR /&gt;bird6 0.38709&lt;BR /&gt;&lt;BR /&gt;where 22/341=0.0645, 66/341=0.1935, 44/341=0.129, 55/341=0.16129, and 132/341=0.38709&lt;BR /&gt;</description>
      <pubDate>Fri, 22 Mar 2019 16:24:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-ERROR-Ambigous-Reference/m-p/545282#M8006</guid>
      <dc:creator>jawhitmire</dc:creator>
      <dc:date>2019-03-22T16:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL ERROR Ambigous Reference</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-ERROR-Ambigous-Reference/m-p/545286#M8007</link>
      <description>Changed 'or' statement to 'and'. Thank you.&lt;BR /&gt;Output performs calculation for just 3 birds. Is there a way to get output for all 6 as follows:&lt;BR /&gt;&lt;BR /&gt;bird result&lt;BR /&gt;&lt;BR /&gt;bird1 0.0645&lt;BR /&gt;bird2 0.0645&lt;BR /&gt;bird3 0.1935&lt;BR /&gt;bird4 0.129&lt;BR /&gt;bird5 0.16129&lt;BR /&gt;bird6 0.38709&lt;BR /&gt;&lt;BR /&gt;where 22/341=0.0645, 66/341=0.1935, 44/341=0.129, 55/341=0.16129, and 132/341=0.38709&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 22 Mar 2019 16:33:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-ERROR-Ambigous-Reference/m-p/545286#M8007</guid>
      <dc:creator>jawhitmire</dc:creator>
      <dc:date>2019-03-22T16:33:39Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL ERROR Ambigous Reference</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-ERROR-Ambigous-Reference/m-p/545294#M8009</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/248885"&gt;@jawhitmire&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What you need is a full join based on your expected result.&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 work.equation1 as
	select  h.bird,
	sum(H.hmass,G.gmass,C.cmass)/(&amp;amp;htotal. + &amp;amp;gtotal. + &amp;amp;ctotal.) as result 
	from work.h_calc as H full join work.g_calc as G
	on H.bird=G.bird
	full join 
	work.c_calc as C
	on  C.bird=H.bird;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;TABLE class="systitleandfootercontainer" border="0" summary="Page Layout" width="100%" frame="void" rules="none" cellspacing="1" cellpadding="1"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="c systemtitle"&gt;The SAS System&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;BR /&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure SQL: Query Results" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l b header" scope="col"&gt;bird&lt;/TH&gt;
&lt;TH class="r b header" scope="col"&gt;result&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;bird1&lt;/TD&gt;
&lt;TD class="r data"&gt;0.064516&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;bird2&lt;/TD&gt;
&lt;TD class="r data"&gt;0.064516&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;bird3&lt;/TD&gt;
&lt;TD class="r data"&gt;0.193548&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;bird4&lt;/TD&gt;
&lt;TD class="r data"&gt;0.129032&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;bird5&lt;/TD&gt;
&lt;TD class="r data"&gt;0.16129&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;bird6&lt;/TD&gt;
&lt;TD class="r data"&gt;0.387097&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Fri, 22 Mar 2019 16:47:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-ERROR-Ambigous-Reference/m-p/545294#M8009</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-22T16:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL ERROR Ambigous Reference</title>
      <link>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-ERROR-Ambigous-Reference/m-p/545295#M8010</link>
      <description>Thank you for the feedback. This was the perfect solution. Jane</description>
      <pubDate>Fri, 22 Mar 2019 16:50:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/PROC-SQL-ERROR-Ambigous-Reference/m-p/545295#M8010</guid>
      <dc:creator>jawhitmire</dc:creator>
      <dc:date>2019-03-22T16:50:48Z</dc:date>
    </item>
  </channel>
</rss>

