BookmarkSubscribeRSS Feed
Arun_23
Calcite | Level 5

I refer to ODBC libraries using the following statement

LIBNAME STATIC ODBC DATASRC = static SCHEMA = DBO USER = <username> PASSWORD = <password>;

I am trying to create a new table within the the Static table in SQL Server using the following code:

proc sql;

create table static.NEW_SQL_TABLE as

select * from static.OLD_SQL_TABLE (obs = 10);

quit;

I get the following error -->

ERROR: CLI Execute Error: [Microsoft][ODBC SQL Server Driver][SQL Server] Invalid object name 'DBO.NEW_SQL_TABLE'.

:[Microsoft][ODBC SQL Server Driver][SQL Server] Statement(s) could not be prepared.

However a simple temporary dataset within SAS works perfectly fine using the below code:

proc sql;

create table TEMP_SQL_TABLE as

select * from static.OLD_SQL_TABLE (obs = 10);

quit;

Can anybody please help me with this? How else will I be able to directly write a SAS dataset into the SQL database (without having to export to csv and then importing back again, which is what I currently do -pardon my ignorance here)?

Thanks a ton.

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

Not particularly familiar with SQL Server so hope this is not too wide of the mark.  In Oracle the schema is a two level dimension, XXXYYY$VVVEEE, so with a $ division.  I am wondering if something along those lines is your issue in the DBO is one level.  There does seem to be something about multi level schemas after 2005 version:

User-Schema Separation

The only other thing I remember from access Oracle is that we had to do something like:

proc sql;

     connect to oracle (path=dddd user=aaa orapw=cccc);

     execute (drop table A_TABLE) by oracle;

     execute (commit) by oracle;

     disconnect from oracle;

quit;

Now of course the above is for OC however, the execute (sql commands) by db connection may be of help.

Hope this helps.

esjackso
Quartz | Level 8

Here are somethings I would look at:

--Have you verified that you have write permissions in the database?

--Have you tried passthru sql to the SQL server? (which is what did in his example to an oracle database... just look up the syntax for SQL Server)

I dont think you mentioned which version of sas or SQL server you are using. This could help solve the issue.

You could always open a ticket with SAS support to see if they could help.

EJ

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
  • 2 replies
  • 1646 views
  • 0 likes
  • 3 in conversation