Hi Experts,
I am trying to get the date value form a table using sql query. But I am getting the following error.
ERROR: ORACLE prepare error: ORA-00923: FROM keyword not found where expected. SQL
statement: SELECT ACCT.number as Acct_id,datepart(ACCT.DATE) AS DT format date9.,ACCT.Num,
Client.Name FROM ACCT,Client
Here is my code:
proc sql;
connect to ORACLE (user="xxxx" password="xxxx" buffsize=5000 path=test);
CREATE TABLE sample AS
SELECT * FROM CONNECTION TO ORACLE
(
SELECT
ACCT.number as Acct_id,
datepart(ACCT.DATE) AS DT format date9.,
ACCT.Num,
Client.Name
FROM
ACCT,
Client
);
quit;
Please suggest if I am doing anything wrong.
Thanks,
The Oracle DATEPART() function works differently than the SAS DATEPART(): https://docs.oracle.com/cd/E57185_01/ESBTR/mdx_datepart.html
Similarly, Oracle will (most likely) not understand DATE9.
Before using explicit passthrough to database system X, you need to have sufficient knowledge of the peculiarities of DBMS X. If in doubt, ask your local Oracle admins.
Your code has syntax errors. You are using the "Pass-Through" feature. "Format's" are exclusive features of SAS, they will not work inside the "Pass-Through" block.
See "Pass-Through"
In addition, oracle has no data type "date", only "date-time", but if your SAS is configured correctly, the SAS itself does the necessary conversions.
Try this code:
proc sql;
connect to ORACLE (user="xxxx" password="xxxx" buffsize=5000 path=test);
CREATE TABLE sample AS
SELECT
Acct_id,
datepart(DATE) as DT format date9.,
Num,
Name
FROM CONNECTION TO ORACLE
(
SELECT
ACCT.number as Acct_id, ACCT.DATE, ACCT.Num, Client.Name
FROM ACCT, Client
);
quit;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.