<?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: I have to join two table but it is giving an error in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/I-have-to-join-two-table-but-it-is-giving-an-error/m-p/632405#M187494</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The reason this is happening is because when you select *, you are telling sas you want to include everything from both the tables, and as SchemeNumber exists on both tables you can't have two variables with the same name. In order to get rid of it, you would need to tell SAS which of the two tables you want to pull SchemeNumber from.&lt;/P&gt;</description>
    <pubDate>Mon, 16 Mar 2020 11:53:16 GMT</pubDate>
    <dc:creator>robulon</dc:creator>
    <dc:date>2020-03-16T11:53:16Z</dc:date>
    <item>
      <title>I have to join two table but it is giving an error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-have-to-join-two-table-but-it-is-giving-an-error/m-p/632399#M187489</link>
      <description>&lt;P&gt;I have to join two table but it is giving an error:&amp;nbsp;&lt;STRONG&gt;Ambiguous reference, column schemenumber is in more than one table&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;I have two table scheme1 and strategies in which there are multiple coloumns, some of the coloumn name have same in both the table.&lt;/P&gt;&lt;P&gt;I am using the following code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table lifepath(keep=schemenumber uniquestrategyid uniquefundid)
as select * from scheme1 as scheme1, strategies as strategies
where schemenumber=schemenumber
and defaultstrategy=uniquestrategyid;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have to join these two table and keep only three coloumns. How can I do that.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Mar 2020 11:35:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-have-to-join-two-table-but-it-is-giving-an-error/m-p/632399#M187489</guid>
      <dc:creator>annypanny</dc:creator>
      <dc:date>2020-03-16T11:35:51Z</dc:date>
    </item>
    <item>
      <title>Re: I have to join two table but it is giving an error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-have-to-join-two-table-but-it-is-giving-an-error/m-p/632400#M187490</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table lifepath(keep=schemenumber uniquestrategyid uniquefundid)
as select * from scheme1 as scheme1, strategies as strategies
where scheme1.schemenumber=strategies.schemenumber
and defaultstrategy=uniquestrategyid;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Mar 2020 11:37:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-have-to-join-two-table-but-it-is-giving-an-error/m-p/632400#M187490</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-03-16T11:37:01Z</dc:date>
    </item>
    <item>
      <title>Re: I have to join two table but it is giving an error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-have-to-join-two-table-but-it-is-giving-an-error/m-p/632401#M187491</link>
      <description>&lt;P&gt;thanks, now it is running but throwing a warning:&amp;nbsp;&lt;STRONG&gt;Variable SchemeNumber already exists on file WORK.LIFEPATH. &lt;/STRONG&gt;How can I get rid of that?&lt;/P&gt;</description>
      <pubDate>Mon, 16 Mar 2020 11:41:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-have-to-join-two-table-but-it-is-giving-an-error/m-p/632401#M187491</guid>
      <dc:creator>annypanny</dc:creator>
      <dc:date>2020-03-16T11:41:51Z</dc:date>
    </item>
    <item>
      <title>Re: I have to join two table but it is giving an error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-have-to-join-two-table-but-it-is-giving-an-error/m-p/632404#M187493</link>
      <description>&lt;P&gt;DO NOT use the asterisk in SQL, especially not when joining tables. ALWAYS use an explicit list of variables, and use aliases to tell SAS which variable from which table to take:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table lifepath as
select
  s1.schemenumber,
  st.uniquestrategyid,
  st.uniquefundid
from scheme1 as s1, strategies as st
where s1.schemenumber=st.schemenumber
and s1.defaultstrategy=st.uniquestrategyid;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Mar 2020 11:53:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-have-to-join-two-table-but-it-is-giving-an-error/m-p/632404#M187493</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-16T11:53:12Z</dc:date>
    </item>
    <item>
      <title>Re: I have to join two table but it is giving an error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-have-to-join-two-table-but-it-is-giving-an-error/m-p/632405#M187494</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;The reason this is happening is because when you select *, you are telling sas you want to include everything from both the tables, and as SchemeNumber exists on both tables you can't have two variables with the same name. In order to get rid of it, you would need to tell SAS which of the two tables you want to pull SchemeNumber from.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Mar 2020 11:53:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-have-to-join-two-table-but-it-is-giving-an-error/m-p/632405#M187494</guid>
      <dc:creator>robulon</dc:creator>
      <dc:date>2020-03-16T11:53:16Z</dc:date>
    </item>
    <item>
      <title>Re: I have to join two table but it is giving an error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-have-to-join-two-table-but-it-is-giving-an-error/m-p/632406#M187495</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/316738"&gt;@annypanny&lt;/a&gt;&amp;nbsp; Whenever you see an error that states ambiguous reference, that essentially means the SQL processor is unable to&amp;nbsp; SELECT/pick the column as the columns are read. The SQL processor expects an alias or in other words&amp;nbsp; a reference that points to the specific table wherein the column exists that needs to be read.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have used alias/reference in the FROM clause to denote the reference&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;from scheme1 as scheme1, strategies as strategies&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, you still need to point the column names with those references as a two level names with those references as a prefix like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;scheme1.schemenumber=strategies.schemenumber&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The same principle applies to the select clause as well and so the select clause ought to be written as&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select scheme1.schemenumber,uniquestrategyid,uniquefundid&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Finally the complete construct is bound to have the following syntax&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
 create table lifepath as
 select scheme1.schemenumber,uniquestrategyid,uniquefundid
 from scheme1 as scheme1, strategies as strategies
 where scheme1.schemenumber=strategies.schemenumber
 and defaultstrategy=uniquestrategyid;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Please refrain from using &lt;STRONG&gt;*&lt;/STRONG&gt; if you are working with production code for the simple reason, leads to ambiguity, confusion and also difficult to maintain should you work with a team of people supporting each other. It's always better to be explicit and clear for you and for your team.&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>Mon, 16 Mar 2020 11:53:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-have-to-join-two-table-but-it-is-giving-an-error/m-p/632406#M187495</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-16T11:53:40Z</dc:date>
    </item>
    <item>
      <title>Re: I have to join two table but it is giving an error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-have-to-join-two-table-but-it-is-giving-an-error/m-p/632408#M187496</link>
      <description>&lt;P&gt;what if I have to pull the values of schemenumber from both the tables&lt;/P&gt;</description>
      <pubDate>Mon, 16 Mar 2020 12:00:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-have-to-join-two-table-but-it-is-giving-an-error/m-p/632408#M187496</guid>
      <dc:creator>annypanny</dc:creator>
      <dc:date>2020-03-16T12:00:45Z</dc:date>
    </item>
    <item>
      <title>Re: I have to join two table but it is giving an error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-have-to-join-two-table-but-it-is-giving-an-error/m-p/632410#M187497</link>
      <description>If you need the values of schemenumber from both tables, you would need to do a full join and use the coalesce function (coalesce(a.schemenumber,b.schemenumber) as schemenumber). This would then merge on and schemenumbers that appear in both tables, but would also include any that appear in the second table but not the first.</description>
      <pubDate>Mon, 16 Mar 2020 12:06:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-have-to-join-two-table-but-it-is-giving-an-error/m-p/632410#M187497</guid>
      <dc:creator>robulon</dc:creator>
      <dc:date>2020-03-16T12:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: I have to join two table but it is giving an error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-have-to-join-two-table-but-it-is-giving-an-error/m-p/632425#M187503</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/316738"&gt;@annypanny&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;what if I have to pull the values of schemenumber from both the tables&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The way your join is built (inner join), that would only give you redundant information. If you want a full join, use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;coalesce(s1.schemenumber,st.schemenumber) as schemenumber&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;in the select.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Mar 2020 13:05:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-have-to-join-two-table-but-it-is-giving-an-error/m-p/632425#M187503</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-16T13:05:11Z</dc:date>
    </item>
    <item>
      <title>Re: I have to join two table but it is giving an error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-have-to-join-two-table-but-it-is-giving-an-error/m-p/632426#M187504</link>
      <description>&lt;P&gt;thanks it is working for men the answer code is here:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table lifepath
as select coalesce(scheme1.schemenumber, strategies.schemenumber), uniquestrategyid, uniquefundid  
as schemenumber from scheme1 full join strategies
on scheme1.schemenumber=strategies.schemenumber
and scheme1.defaultstrategy=strategies.uniquestrategyid;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Mar 2020 13:13:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-have-to-join-two-table-but-it-is-giving-an-error/m-p/632426#M187504</guid>
      <dc:creator>annypanny</dc:creator>
      <dc:date>2020-03-16T13:13:57Z</dc:date>
    </item>
  </channel>
</rss>

