<?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 join with same variable names in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-join-with-same-variable-names/m-p/632428#M77814</link>
    <description>&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;&lt;SPAN&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 year and season 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 year and season from.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 16 Mar 2020 13:36:27 GMT</pubDate>
    <dc:creator>annypanny</dc:creator>
    <dc:date>2020-03-16T13:36:27Z</dc:date>
    <item>
      <title>proc sql join with same variable names</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-join-with-same-variable-names/m-p/48781#M13217</link>
      <description>I have following codes:&lt;BR /&gt;
&lt;BR /&gt;
data daily;&lt;BR /&gt;
input ID $ YEAR  SEASON $ RAINFALL ;&lt;BR /&gt;
CARDS;&lt;BR /&gt;
1 1989 SUMMER 20&lt;BR /&gt;
2 1990 FALL 15&lt;BR /&gt;
3 1990 SUMMER 25&lt;BR /&gt;
4 1989 WINTER 11&lt;BR /&gt;
;&lt;BR /&gt;
RUN;&lt;BR /&gt;
data TEMP;&lt;BR /&gt;
input YEAR SEASON $ TEMP;&lt;BR /&gt;
CARDS;&lt;BR /&gt;
1989 WINTER 28&lt;BR /&gt;
1989 SPRING 52&lt;BR /&gt;
1989 SUMMER 80&lt;BR /&gt;
1989 FALL   63&lt;BR /&gt;
1990 WINTER 33&lt;BR /&gt;
1990 SPRING 56&lt;BR /&gt;
1990 SUMMER 78&lt;BR /&gt;
1990 FALL   65&lt;BR /&gt;
;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;B&gt;PROC SQL;&lt;BR /&gt;
CREATE TABLE TEST AS&lt;BR /&gt;
SELECT	U1.*,&lt;BR /&gt;
		U2.*&lt;BR /&gt;
FROM DAILY AS U1 LEFT JOIN TEMP AS U2&lt;BR /&gt;
ON U1.YEAR=U2.YEAR AND U1.SEASON=U2.SEASON&lt;BR /&gt;
;&lt;BR /&gt;
QUIT&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
There are such warning message in the log:&lt;BR /&gt;
&lt;BR /&gt;
&lt;B&gt;WARNING: Variable YEAR already exists on file WORK.TEST.&lt;BR /&gt;
WARNING: Variable SEASON already exists on file WORK.TEST&lt;/B&gt;&lt;BR /&gt;
&lt;BR /&gt;
How can we re-write proc sql to avoid such warning message? I know one way is to explicitly select every single variable like following codes:&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL;&lt;BR /&gt;
CREATE TABLE TEST AS&lt;BR /&gt;
SELECT	U1.*,&lt;BR /&gt;
		&lt;B&gt;U2.temp&lt;/B&gt;&lt;BR /&gt;
FROM DAILY AS U1 LEFT JOIN TEMP AS U2&lt;BR /&gt;
ON U1.YEAR=U2.YEAR AND U1.SEASON=U2.SEASON&lt;BR /&gt;
;&lt;BR /&gt;
QUIT&lt;BR /&gt;
&lt;BR /&gt;
however i am wondering if there is other way, such as using COALESCE function to coalesce those Variables with same names?</description>
      <pubDate>Tue, 12 Apr 2011 20:29:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-join-with-same-variable-names/m-p/48781#M13217</guid>
      <dc:creator>littlestone</dc:creator>
      <dc:date>2011-04-12T20:29:42Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql join with same variable names</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-join-with-same-variable-names/m-p/48782#M13218</link>
      <description>You need to name these variables which are in both tables manually.&lt;BR /&gt;
Such as&lt;BR /&gt;
[pre]&lt;BR /&gt;
u1.year as u1_year,u2.year as u2_year&lt;BR /&gt;
...etc&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp

Message was edited by: Ksharp</description>
      <pubDate>Wed, 13 Apr 2011 03:46:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-join-with-same-variable-names/m-p/48782#M13218</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-04-13T03:46:04Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql join with same variable names</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-join-with-same-variable-names/m-p/48783#M13219</link>
      <description>Hi Two ways are there to execute the task....&lt;BR /&gt;
1. by proc sql;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table season as&lt;BR /&gt;
select d.*,t.year as yeart, t.season as seasont,temp as tempreture from daily d,temp t&lt;BR /&gt;
where d.year=t.year and d.season=t.season;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
2. in dataset by merge keyword&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=daily;&lt;BR /&gt;
by year season;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sort data=temp;&lt;BR /&gt;
by year season;&lt;BR /&gt;
run;&lt;BR /&gt;
data final;&lt;BR /&gt;
merge temp daily(in=ind);&lt;BR /&gt;
by year season;&lt;BR /&gt;
if ind=1;&lt;BR /&gt;
run;</description>
      <pubDate>Wed, 13 Apr 2011 07:41:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-join-with-same-variable-names/m-p/48783#M13219</guid>
      <dc:creator>sss</dc:creator>
      <dc:date>2011-04-13T07:41:32Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql join with same variable names</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-join-with-same-variable-names/m-p/48784#M13220</link>
      <description>Proc sql has an undocumented NOWARN option that will get rid of this warning message.&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL NOWARN;&lt;BR /&gt;
CREATE TABLE TEST AS&lt;BR /&gt;
SELECT U1.*,&lt;BR /&gt;
U2.*&lt;BR /&gt;
FROM DAILY AS U1 LEFT JOIN TEMP AS U2&lt;BR /&gt;
ON U1.YEAR=U2.YEAR AND U1.SEASON=U2.SEASON&lt;BR /&gt;
;&lt;BR /&gt;
QUIT;</description>
      <pubDate>Wed, 13 Apr 2011 09:43:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-join-with-same-variable-names/m-p/48784#M13220</guid>
      <dc:creator>polingjw</dc:creator>
      <dc:date>2011-04-13T09:43:31Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql join with same variable names</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-join-with-same-variable-names/m-p/48785#M13221</link>
      <description>Thank you for all for suggestions.</description>
      <pubDate>Wed, 13 Apr 2011 16:00:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-join-with-same-variable-names/m-p/48785#M13221</guid>
      <dc:creator>littlestone</dc:creator>
      <dc:date>2011-04-13T16:00:36Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql join with same variable names</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/proc-sql-join-with-same-variable-names/m-p/632428#M77814</link>
      <description>&lt;P&gt;hi,&lt;/P&gt;&lt;P&gt;&lt;SPAN&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 year and season 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 year and season from.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Mar 2020 13:36:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/proc-sql-join-with-same-variable-names/m-p/632428#M77814</guid>
      <dc:creator>annypanny</dc:creator>
      <dc:date>2020-03-16T13:36:27Z</dc:date>
    </item>
  </channel>
</rss>

