<?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 with overlap columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-with-overlap-columns/m-p/719797#M222912</link>
    <description>&lt;P&gt;You did not post the error message you got. I guess the overlapping is next part of your code - the bold part:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;create table &lt;STRONG&gt;want&lt;/STRONG&gt; as select a.*, &amp;amp;list2 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;from &lt;STRONG&gt;want&lt;/STRONG&gt; as a &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;join have as b &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;on a.id=b.id; quit;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Beyond, in both sql you&amp;nbsp;&lt;STRONG&gt;create table want&lt;/STRONG&gt; so the 2nd sql override the 1st.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;You may rename it as want1, want2 then you will not override results none have overlapping:&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1; 
input id var1 var2 var3 var4;
datalines;
1 1 1 1 4
2 3 4 3 5
3 4 5 6 9
;run;

data id_file; input id name $;
datalines;
1 name1
2 name2
;run;

%let list1 = var1, var2, var3;
%let list2 = var2, var3, var4;

proc sql;
create table want1 as select a.*, &amp;amp;list1 
       from id_file as a 
	   join have1 as b 
	   on a.id=b.id; quit;

proc sql;
create table want2 as select a.*, &amp;amp;list2 
       from want1 as a 
	   join have1 as b 
	   on a.id=b.id; quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 17 Feb 2021 05:08:00 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2021-02-17T05:08:00Z</dc:date>
    <item>
      <title>PROC SQL with overlap columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-with-overlap-columns/m-p/719793#M222911</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;I want to run 2 proc SQL with list of columns chosen embedded in 2 macro variable &amp;amp;list1 and &amp;amp;list2.&lt;/P&gt;
&lt;P&gt;The trouble is that some element in the 2 lists are overlap which make sql return error.&lt;/P&gt;
&lt;P&gt;My real work requires to run 2 SQL procedures.&lt;/P&gt;
&lt;P&gt;Can you please help me to solve it?&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;HHCFX&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1; 
input id var1 var2 var3 var4;
datalines;
1 1 1 1 4
2 3 4 3 5
3 4 5 6 9
;run;

data id_file; input id name $;
datalines;
1 name1
2 name2
;run;

%let list1 = var1, var2, var3;
%let list2 = var2, var3, var4;

proc sql;
create table want as select a.*, &amp;amp;list1 from id_file as a join have as b on a.id=b.id; quit;

proc sql;
create table want as select a.*, &amp;amp;list2 from want as a join have as b on a.id=b.id; quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2021 04:21:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-with-overlap-columns/m-p/719793#M222911</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2021-02-17T04:21:43Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL with overlap columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-with-overlap-columns/m-p/719797#M222912</link>
      <description>&lt;P&gt;You did not post the error message you got. I guess the overlapping is next part of your code - the bold part:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;create table &lt;STRONG&gt;want&lt;/STRONG&gt; as select a.*, &amp;amp;list2 &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;from &lt;STRONG&gt;want&lt;/STRONG&gt; as a &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;join have as b &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;on a.id=b.id; quit;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Beyond, in both sql you&amp;nbsp;&lt;STRONG&gt;create table want&lt;/STRONG&gt; so the 2nd sql override the 1st.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;You may rename it as want1, want2 then you will not override results none have overlapping:&lt;/FONT&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1; 
input id var1 var2 var3 var4;
datalines;
1 1 1 1 4
2 3 4 3 5
3 4 5 6 9
;run;

data id_file; input id name $;
datalines;
1 name1
2 name2
;run;

%let list1 = var1, var2, var3;
%let list2 = var2, var3, var4;

proc sql;
create table want1 as select a.*, &amp;amp;list1 
       from id_file as a 
	   join have1 as b 
	   on a.id=b.id; quit;

proc sql;
create table want2 as select a.*, &amp;amp;list2 
       from want1 as a 
	   join have1 as b 
	   on a.id=b.id; quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2021 05:08:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-with-overlap-columns/m-p/719797#M222912</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-02-17T05:08:00Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL with overlap columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-with-overlap-columns/m-p/719946#M222965</link>
      <description>&lt;P&gt;Thanks for looking into the issue.&lt;/P&gt;
&lt;P&gt;For the last query, the error is below since var2 and var3 are in both data.&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;P&gt;ERROR: Ambiguous reference, column var2 is in more than one table.&lt;BR /&gt;ERROR: Ambiguous reference, column var3 is in more than one table.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2021 15:54:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-with-overlap-columns/m-p/719946#M222965</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2021-02-17T15:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL with overlap columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-with-overlap-columns/m-p/720011#M223001</link>
      <description>&lt;P&gt;Please post your expected output.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2021 19:11:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-with-overlap-columns/m-p/720011#M223001</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-02-17T19:11:40Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL with overlap columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-with-overlap-columns/m-p/720013#M223003</link>
      <description>&lt;P&gt;LIST1 is used in the first SQL. As VARn (n=1 to 3) are in HAVE1 dataset only, and HAVE1 its assigned in sql as b then the code you can assign:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;%let list1 = b.var1, b.var2, b.var3;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;LIST2 is used in the second sql. AS variables var2 and var3 exists in both datasets: WANT1 and HAVE1 yo have to decide from which dataset to select those variables - a=WANT1 (a.var2, a.var3)&lt;/P&gt;
&lt;P&gt;or b=HAVE1 (b.var2, b,var3).&lt;/P&gt;</description>
      <pubDate>Wed, 17 Feb 2021 19:31:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-with-overlap-columns/m-p/720013#M223003</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-02-17T19:31:46Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SQL with overlap columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-with-overlap-columns/m-p/720036#M223012</link>
      <description>&lt;P&gt;It is quite frustrating to help you.&amp;nbsp; You must present a want table, somehow, or else we are just guessing what you mean.&amp;nbsp; Do you want a table like this, or something else?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want; 
input id var1 var2 var3 var2_2 var3_2 var4;
datalines;
name1 1 1 1 1 1 4
name2 3 4 3 4 3 5
;run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 17 Feb 2021 20:55:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-with-overlap-columns/m-p/720036#M223012</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2021-02-17T20:55:12Z</dc:date>
    </item>
  </channel>
</rss>

