BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ranjeeta
Pyrite | Level 9

proc sql;
488! create table NACRS_AA_COSTsql as
489 select *
490 from NACRS_AA_1 as a, Costing_1 as b
491 where a.CIHI_KEY=b.CIHI_KEY
492 ;
WARNING: Variable CIHI_KEY already exists on file WORK.NACRS_AA_COSTSQL.
NOTE: Table WORK.NACRS_AA_COSTSQL created, with 1171 rows and 81 columns.

493 quit;
NOTE: PROCEDURE SQL used (Total process time):
real time 0.39 seconds
cpu time 0.39 seconds

 

Hello Can someone please advise why I get the warning message
 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Dataset option should follow dataset and not the alias 🙂

 

Costing_1 (rename=(CIHI_KEY=key2)) as b

View solution in original post

12 REPLIES 12
novinosrin
Tourmaline | Level 20

"Hello Can someone please advise why I get the warning message"  -- this is because of the ambiguity for the sql processor to determine which CIHI_KEY for select clause to pick as that column is present in both your tables referred in from clause.

 

 

http://support.sas.com/kb/9/963.html

 

Also, try to avoid using * in production code as far as possible. 

 

 

Ranjeeta
Pyrite | Level 9
thankyou in this case the ihikey is picked from which table ?
Alsohw would i specify to select cihikey from one table but i also need all the columns from both tables
I dont have training in sql so asking basic q's
novinosrin
Tourmaline | Level 20

The column that is kept is from the first table in the from clause that contains that variable.

 

Unfortunately, you will have to type  like

 

select a.col1,a.col2,....a.coln , b.col,b.coln

 

Do not specify the key variable in b. series of col names

Reeza
Super User
Try the FEEDBACK option. Add it to the PROC SQL statement and then check your log. You can copy the query and use that instead.

Proc sql feedback;
Create table want as
Select *
From sashelp.class as a, sashelp.class as b
Where a.name=b.name;
Quit;

This is a useless query but should illustrate your issue.
Ranjeeta
Pyrite | Level 9
Thankyou
mkeintz
PROC Star

@novinosrin:

 

But you CAN avoid extensive variable lists and preserve usage of "select *" with judicious use of the data set name parameters RENAME and DROP.:

 

proc sql;
 create table NACRS_AA_COSTsql (drop=key2) as
 select *
   from NACRS_AA_1 as a, Costing_1 (rename=(cihi_key=key2)) as b
   where a.CIHI_KEY=b.KEY2
   ;
quit;
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
novinosrin
Tourmaline | Level 20

Nice idea 🙂

Ranjeeta
Pyrite | Level 9
Thankyou !!
novinosrin
Tourmaline | Level 20

@Ranjeeta  To what you wrote as basic, doesn't seem basic anymore considering you take a look at @mkeintzMark's idea, i.e slick use of dataset options and elegantly keeping *  to select all.  I hope you took note of that as I did. 

Ranjeeta
Pyrite | Level 9
thankyou
I am getting an error
proc sql;
102! create table NACRS_AA_COSTsql (drop=key2) as
103 select *
104 from NACRS_AA_1 as a, Costing_1 as b (rename=(CIHI_KEY=key2))
-
22
76
ERROR 22-322: Syntax error, expecting one of the following: GROUP, HAVING, ORDER, WHERE.

ERROR 76-322: Syntax error, statement will be ignored.

105 where a.CIHI_KEY=b.key2
106 ;
107 quit;
novinosrin
Tourmaline | Level 20

Dataset option should follow dataset and not the alias 🙂

 

Costing_1 (rename=(CIHI_KEY=key2)) as b
Ranjeeta
Pyrite | Level 9
Many thanks 🙂

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 12 replies
  • 952 views
  • 0 likes
  • 4 in conversation