08-19-2014 02:28 AM
Hi, Is there any SHORTER way of writing the below piece of code %if &dsn. = pavan and (%substr("&ym.",6,2) = 02 or %substr("&ym.",6,2) = 03 or %substr("&ym.",6,2) = 05 or %substr("&ym.",6,2) = 06 or %substr("&ym.",6,2) = 08 or %substr("&ym.",6,2) = 09 or %substr("&ym.",6,2) = 11 or %substr("&ym.",6,2) = 12) %then %do; Here ym and dsn are macro variables.
08-19-2014 04:43 AM
agree, we can use IN operator in the macro. However it is important to know that we cannot use the IN operator directly as we use in the datastep. Macro does not recognize the IN operator. There are options which make the macro recognize the IN operator, also we need to make the delimiter to be recognized by the macro and even this can be made recognizable by macros using the options.
there are two options which does these two things
minoperator and mindelimiter
so please try something like below in your actual code to reduce the code and to simplify it
also please try to avoid using the quotation marks for the parameters in within the macro, like %substr("&ym",6,2) , instead use only %substr(&ym,6,2). Macro recognized every character the text. so no quotations needed.
options minoperator mindelimiter=',';
%if &dsn.=pavan and %substr(&ym,6,2) in (02,03,05,06,08,09,11,12) %then %do;
proc print data=sashelp.class;
08-19-2014 05:06 AM
Well, I can think of several possible answers to this, but it very dependant on what you are doing outside that bit of code. For instance, from the code given I do not see a reason why you would need to be doing this in macro code, it doesn't seem generic enough for such a thing. Try moving it back to standard SAS, then you have full functionality. Without the surrounding code its hard to say, but I assume you are dealing with year part of a date?