Hi Everybody!
I am connected to a database using a odbc connection and I need to create a view in database. I have written the following code:
libname test odbc noprompt="uid=username;
pwd=password;
dsn=mydatabase;"
stringdates=yes;
Proc Sql;
create view test.table1 as
select * from orders;
Quit;
I got the following error message
ERROR: The CREATE VIEW statement cannot be processed directly by the database.
ERROR: Create View failed.
Could somebody help me create the view in the database.
Your help is highly appreciated.
Ram
This explicit pass-through SQL (vs implicit in your original post) works fine for me:
PROC SQL;
connect to oracle (path='' user='' password='');
execute( create view LEAD_ACCOUNT_V as
select *
from "Lead_Account"
) by Oracle;
quit;
Personally I would default back to pass-through:
proc sql;
connect to db (...);
execute by db (create view ...);
disconnect from db;
quit;
(Note syntax is from memory so may need a bit of tweaking).
This would send the SQL through to the DB to process.
This explicit pass-through SQL (vs implicit in your original post) works fine for me:
PROC SQL;
connect to oracle (path='' user='' password='');
execute( create view LEAD_ACCOUNT_V as
select *
from "Lead_Account"
) by Oracle;
quit;
Skillman,
There was some issues with my connectivity. Looking at your code I was able to fix it. Now both the approaches (one that I posted earlier ) and you provided work. Thank you and I appreciate your help.
Hi Ram,
If you are using SAS 9.4, you can do this with the the DBIDIRECTEXEC system option. This code uses ACCESS to PostgreSQL. It is worth noting that the explicit pass-thru method gives you more control and may be preferable, but this does work. I ran this with SAS 9.4M2.
libname mypg postgres server=localhost database=mydb user=myuser pw=mypasswd;
proc sql;
create table mypg.cars
as select *
from sashelp.cars;
quit;
options dbidirectexec sastrace=',,,d' sastraceloc=saslog nostsuffix;
/*create the view */
proc sql;
create view mypg.jeeps
as
select *
from mypg.cars
where make='Jeep';
quit;
/* see if it worked. It should return 3 */
proc sql;
select count(*) from mypg.jeeps;
quit;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.
Find more tutorials on the SAS Users YouTube channel.