Im not following your question, the where statement and the orderdate your are referring to are not in your code? Post your entire code and some sample data if necesarry
Several issues to consider.
First, instead of using DATE. as the format, use DATE9. as the format. That way your macro variable will resolve to '22apr2017'd (including a four-digit year is safer).
Second, you cannot accurately compare a datetime to a date. They take on a different range of values. If ORDER_DATE is truly a datetime, you could use:
Where datepart(al1.order_date) between &dt. And &dt1.
Third, it's not clear what is in ORDER_DATE (is it really a datetime, a character string, or something else entirely). But if it's really a datetime, the combination of the earlier steps should work.
Aside from the fact that you are comparing date and datetime values, which will not work as expected, you do not need the date/datetime literal formatting in macro variables.
data _null_;
start_date = today() - 2;
end_date = today() - 2;
if weekday(start_date) = 1 then start_day = start_day - 1;
call symput('dt',put(start_date,best.));
call symput('dt1',put(end_date,best.));
run;
stores the raw date values as simple numbers, which are semantically the same. And it avoids all the hassles with the quotes.
Whilst your question has been answered, I am going to ask you this question. You have logic to determine start and end date, so why are you going through the process of creating macro variables of the resolved logic, then using that in your program. This is simple using macro for the sake of using macro, it adds nothing but complication to an otherwise simple statement. This all derives down to:
where a1.order_date = today() - 2;
(assumes order date is numeric). So why do you have all that extra code doing absolutely nothing? Even if end date is different to start (which it isn't in your example):
where a1_order_date between today() -2 and today() + 2;
Still doesn't need all the faff.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.