BookmarkSubscribeRSS Feed
littlestone
Fluorite | Level 6
I have following codes:

data daily;
input ID $ YEAR SEASON $ RAINFALL ;
CARDS;
1 1989 SUMMER 20
2 1990 FALL 15
3 1990 SUMMER 25
4 1989 WINTER 11
;
RUN;
data TEMP;
input YEAR SEASON $ TEMP;
CARDS;
1989 WINTER 28
1989 SPRING 52
1989 SUMMER 80
1989 FALL 63
1990 WINTER 33
1990 SPRING 56
1990 SUMMER 78
1990 FALL 65
;
RUN;
PROC SQL;
CREATE TABLE TEST AS
SELECT U1.*,
U2.*
FROM DAILY AS U1 LEFT JOIN TEMP AS U2
ON U1.YEAR=U2.YEAR AND U1.SEASON=U2.SEASON
;
QUIT


There are such warning message in the log:

WARNING: Variable YEAR already exists on file WORK.TEST.
WARNING: Variable SEASON already exists on file WORK.TEST


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:

PROC SQL;
CREATE TABLE TEST AS
SELECT U1.*,
U2.temp
FROM DAILY AS U1 LEFT JOIN TEMP AS U2
ON U1.YEAR=U2.YEAR AND U1.SEASON=U2.SEASON
;
QUIT

however i am wondering if there is other way, such as using COALESCE function to coalesce those Variables with same names?
5 REPLIES 5
Ksharp
Super User
You need to name these variables which are in both tables manually.
Such as
[pre]
u1.year as u1_year,u2.year as u2_year
...etc

[/pre]



Ksharp Message was edited by: Ksharp
sss
Fluorite | Level 6 sss
Fluorite | Level 6
Hi Two ways are there to execute the task....
1. by proc sql;
proc sql;
create table season as
select d.*,t.year as yeart, t.season as seasont,temp as tempreture from daily d,temp t
where d.year=t.year and d.season=t.season;
quit;

2. in dataset by merge keyword

proc sort data=daily;
by year season;
run;
proc sort data=temp;
by year season;
run;
data final;
merge temp daily(in=ind);
by year season;
if ind=1;
run;
polingjw
Quartz | Level 8
Proc sql has an undocumented NOWARN option that will get rid of this warning message.

PROC SQL NOWARN;
CREATE TABLE TEST AS
SELECT U1.*,
U2.*
FROM DAILY AS U1 LEFT JOIN TEMP AS U2
ON U1.YEAR=U2.YEAR AND U1.SEASON=U2.SEASON
;
QUIT;
littlestone
Fluorite | Level 6
Thank you for all for suggestions.
annypanny
Quartz | Level 8

hi,

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.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 11104 views
  • 0 likes
  • 5 in conversation