04-25-2017 12:56 AM
04-25-2017 01:45 AM
04-25-2017 01:50 AM
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.
04-25-2017 02:20 AM
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.
04-25-2017 04:08 AM
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.