06-15-2015 04:10 PM
I am using %IF %THEN and it works sometimes as expected. Sometimes it does not work as expected.
The following code does not work when i put "mean" in quotes -
options minoperator mlogic;
%macro missing (method=);
%if %lowcase(&method.) = "mean" or %lowcase(&method.) = "median" %then %do;
%put type = "mean or median";
%put type = "zero";
When i replace the third line of code to : %if %lowcase(&method.) = mean or %lowcase(&method.) = median %then %do; , the code works.
06-15-2015 04:29 PM
You likely have no reason to use a quoted-string and it's giving the SAS macro language compilation issues - review the SAS.COM support site DOC / reference material -- search argument:
quoted strings macro language site:sas.com
06-15-2015 04:38 PM
Thanks for your reply. Sometimes the code works with quotes. I don't understand it. Could you please provide me the link? I searched on sas support site, didn't find the exact link.
06-16-2015 01:28 AM
To help you a little with wrapping your mind about this:
%if %lowcase(&method.) = mean
%if "%lowcase(&method.)" = "mean"
will also work
%if %lowcase(&method.) = "mean"
%if "%lowcase(&method.)" = mean
Since the macro language only knows type char, no quotes are needed for constants.
To further illustrate this, try:
and look at the log.
06-15-2015 05:07 PM
One principle to keep in mind is that this comparison is false:
%if mean = "mean" %then %do;
Macro language does not require quotes. Thus this compares four characters (on the left of the equal sign) to six characters (to the right of the equal sign). In macro language, four characters can never equal six characters.
06-15-2015 09:09 PM
In regular SAS code you use quotes around literal strings to distinguish them from numeric literals, keywords or variable names. But in macro logic quotes are not treated differently from other characters. So it is the same as if you tried to test:
%if %lowcase(&method) = XmethodX %then ....
06-16-2015 04:17 AM
Macro language only has character datatype. There is no numeric datatype in Macro language. Hence quotations are not needed. If the value has quotes then you have to compare using the quotes else you dont need the quotes.