I don't think your %let statement is correct, as SAS would read the value of startdate as "today()-1". The below macro will create a startdate and an enddate for the createdate filter. If the current day you run it is Monday, it will set startdate 3 days ago and enddate to yesterday. If the current day you run it is not a Monday, it will set both startdate and enddate to yesterday. I also modify your where statement in the SQL procedure to call the dates with a date literal. Hope this helps!
%macro createdate;
%let today=%sysfunc(today(),date9.);
%let day=%sysfunc(weekday("&today"d));
%if &day=2 %then %do;
%let startdate=%sysfunc(intnx(DAY,"&today"d,-3),date9.);
%let enddate=%sysfunc(intnx(DAY,"&today"d,-1),date9.);
%end;
%else %do;
%let startdate=%sysfunc(intnx(DAY,"&today"d,-1),date9.);
%let enddate=%sysfunc(intnx(DAY,"&today"d,-1),date9.);
%end;
%put startdate= &startdate enddate= &enddate;
%mend;
%createdate;
proc sql;
create table order as
select id, createdate
from x.table
where "&startdate"d<= createdate <="&enddate"d;
quit;
... View more