Search code examples
sqldatesassas-macro

How to set macro condition for day of today in any of list


I wanna set the code run at days: 5,11,16,22,28 monthly but it doesn't work.

%if %sysfunc(day(%sysfunc(today()))) in (5,11,16,22,28) %then %do

How can I fix it? Thanks much.


Solution

  • The IN operator works in a SAS 9.2 Macro but you need to define system options. The MINOPERATOR (Macro-In-Operator) must be turned on and in your case, the MINDELILITER too must be specified as you are using comma delimited values.
    More information can be found in Getting the IN operator to FUNCTION inside a SAS® Macro

    options minoperator mindelimiter=',';
    %if %sysfunc(day(%sysfunc(today())-1)) in (5,11,16,22,28) %then %do;
        %put do smth...;
    %end; 
    
    do smth...
    

    Notice the -1 in the above example to replicate March 22.