BookmarkSubscribeRSS Feed
sanjay1
Obsidian | Level 7

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,

 

 

2 REPLIES 2
Kurt_Bremser
Super User

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.

dcmacedo
Obsidian | Level 7

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1315 views
  • 2 likes
  • 3 in conversation