I have created a macro variable which is the datetime at the time the program is run less one month, formatted to datetime20:
%let startDate = %sysfunc(intnx(dtmonth, %sysfunc(datetime()), -1), datetime20.);
This part works correctly (if I run it right now, it returns 01JUL2015:00:00:00), but what I want to do is subset a dataset based on this date in a PROC SQL statement. Basically I want to keep everything where the date occurs in the last month. My code is:
proc sql;
create table work.last_month as
select * from work.existing_table
where date >= &startDate.;
quit;
The column "date" and the variable "startDate" are both of type 'datetime20', but it is still throwing an error:
ERROR 22-322: Syntax error, expecting one of the following: ;, !, !!, &, *, **, +, -, /, <, <=, <>, =, >, >=, AND, EQ, EQT, EXCEPT, GE, GET, GROUP, GT, GTT, HAVING, INTERSECT, LE, LET, LT, LTT, NE, NET, NOT, OR, ORDER, OUTER, UNION, ^, ^=, |, ||, ~, ~=.
I don't know why it is throwing this error. What am I doing wrong?
Thanks!