I am trying to write a SAS macro, in which I need to loop a date range and use the date in the where condition in PROC SQL step. At the same time, I have to use a path through in the PROC SQL step.
The start_date field in table1 is in the datetime format, i.e. '15mar2021:00:00:00'.
I tried to convert the date format for &i in the where clause to match the format of start_date field in table1. I tried below query but got this error: ERROR: CLI describe error: [Oracle][ODBC][Ora]ORA-00923: FROM keyword not found where expected
%macro date_delq(start,end);
%let start=%sysfunc(inputn(&start,anydtdte9.));
%let end=%sysfunc(inputn(&end,anydtdte9.));
%do i= &start %to &end;
proc sql;
connect using admin as server;
create table delq_&i as
select * from connection to server(
select *
from table1
where start_date= CONVERT(datetime,&i,106)
);
run;
%end;
%mend date_delq;
%date_delq(01mar2021,02mar2021);
Thank you for your help!
CONVERT(datetime,&i,106)
looks like SQL Server syntax to me. If startdate is aDATE
column as it should be (DATE
is Oracle's inappropriate name for datetime), then it should suffice toselect * from table1 where start_date = &i
. If despite its name the start_date has a time part you want to get rid of, you can truncate it to date only by applyingTRUNC
:where trunc(start_date) = &i
. – Thorsten KettnerTO_DATE
. Make sure to specify the format used in &i, e.g.to_date(&i, 'yyyy-mm-dd')
if &i is a string containing a four -digit year, a dash, a two-digt month, a dash, and a two-digit day. – Thorsten Kettner