I'm trying to extract data from date range (set by start_date and end_date variables defined in the null step).
Usually I would do this using passthru PROC SQL, as follows:
PROC SQL;
CONNECT TO ORACLE AS xxxxx (AUTHDOMAIN="xxxxx" PATH=xxxxx preserve_comments);
CREATE TABLE
work.new_data AS
SELECT
*
FROM
CONNECTION TO xxxxx (SELECT /*+parallel(16)*/ var1, var2, var3
FROM
oracle_data
WHERE date >= &start_date. AND date <= &end_date.);
DISCONNECT FROM xxxxx;
QUIT;
This extracts the data much more efficiently than doing it through a data step or pulling all the data and then filtering it.
The problem is with this particular dataset I'm using, the datetime is stored as a string in the format "DD/MM/YYYY HH:MM:SS". I know how to convert this normally in a data step or such, but the problem is I cannot convert it or interpret it as a date in the PROC SQL passthru stage.
Replacing the WHERE step with any SAS function like below throws an "Oracle Prepare Error" as it doesn't recognize the functions. I've also tried using SQL functions for something similar in the past and they also didn't work and I didn't manage to find a solution.
WHERE DATEPART(INPUT(rtp_date,anydtdtm.)) >= &start_date.)
Is it possible to interpret a string as datetime in the passthru stage and use it for filtering? Or is there perhaps another way to do this which is still more efficient than pulling everything or performing a data step directly onto the oracle data?
TO_DATE()
function? – Tom&start_date
and&end_date
to be the full date time or just the date part of the datetime? – Richard