%LET DATE = '31AUG2016'D; %LET DATE1 = INTNX('MONTH',&DATE,-1,'E'); /* JULY */ %LET DATE2 = INTNX('MONTH',&DATE,-2,'E'); /*JUNE*/ DATA TEST; SET WAREHOUSE; WHERE AS_OF_DATE IN (&DATE, &DATE1, &DATE2); RUN; This is strictly a matter of personal coding style, but the style I've developed over the years is: 1) I don't embed "syntax" in my macro variables. I want my macro variables to only contain data. 2) For macro variables containing date, time, or datetime, I prefer stroring them as date/time/datetime literals. It often makes the log look better, such as the echoing of the where clause in the data step above. 3) Even with SQL Server passthrough, where date literals must be single-quoted, I use either: A) WHERE DATE BETWEEN %bquote('&startdate') and %bquote('&enddate'); or B) %let q=%str(%'); WHERE DATE BETWEEN &q&startdate&q and &q&enddate&q; I used to use B), then a colleague put me onto the %bquote() macro function. Now I think A looks better, even with the extra keystrokes - I just think it looks clearer. So, this then becomes: %LET DATE = 31AUG2016; * or even %LET DATE = %sysfunc(INTNX(MONTH,"12AUG2016"d,0,E),date9.); * to ensure the EOM ;
%LET DATE1 = %sysfunc(INTNX(MONTH,"&DATE"d,-1,E),date9.); /* JULY */
%LET DATE2 = %sysfunc(INTNX(MONTH,"&DATE"d,-2,E),date9.); /*JUNE*/
%PUT &=DATE &=DATE1 &=DATE2; * for debugging ;
DATA TEST;
SET WAREHOUSE;
WHERE AS_OF_DATE IN ("&DATE"d, "&DATE1"d, "&DATE2"d);
RUN; Run that and see how the log looks cleaner, with the date literals displayed in the where clause, instead of some number which represents the date. See the doc for the %sysfunc function and the use of the optional <format> to format the output. HTH...
... View more