Hi, can anyone help?
I have this statment:
%IF (&cur_period = &srt_period1) .......
The LOG are:
SYMBOLGEN: Macro variable CUR_PERIOD resolves to 2013-11
SYMBOLGEN: Macro variable SRT_PERIOD1 resolves to 2012-10
MLOGIC(BUILD_STRING_2): %IF condition (&Cur_period = &srt_period1) is TRUE
I think it should be FALSE. Any hints? Thanks!
Of course it is true. 2013-11 is 2002 and 2012-10 is also 2002.
If you want the implied %eval() in your %IF to treat this formula's as strings then add quotes or something else.
%if ("&Cur_period" = "&srt_period1") ...
or
%if (X&Cur_period = X&srt_period1) ...
Of course it is true. 2013-11 is 2002 and 2012-10 is also 2002.
If you want the implied %eval() in your %IF to treat this formula's as strings then add quotes or something else.
%if ("&Cur_period" = "&srt_period1") ...
or
%if (X&Cur_period = X&srt_period1) ...
Tom,
Interestingly enough(??), the last variation won't work. The hyphen still gets interpreted as subtraction. However, now the presence of "X" causes an error because there is a character value within the arithmetic expression.
Right. Either need to either quote it or macro quote it. But interesting the presence of the non digit causes SAS to give an error that shows what is really happening.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:
X2013-11X=X2011-10X
That's a good one for a puzzle book!
Those dashes look like substraction to the macro processor. There is an implied %EVAL() called by the %IF statement.
So
%IF 2013-11= 2012-10
Becomes
%IF (2013-11)=(2012-10)
i.e.
%if 2002=2002
Solution is to add some macro quoting so that the dash isn't seen as a subsraction sign. Something like:
%macro check(dummy); %local cur_period strt_period1; %let cur_period=2013-11; %let strt_period1=2012-10; %put WITHOUT quoting ; %if &cur_period=&strt_period1 %then %put &cur_period EQUAL &strt_period1; %else %put &cur_period NOT EQUAL &strt_period1; %put WITH quoting: ; %if %superq(cur_period)=%superq(strt_period1) %then &cur_period EQUAL &strt_period1; %else %put &cur_period NOT EQUAL &strt_period1; %mend check; %check()
Thank you all for those hints. It did answer my question. I did forget about some basics in macro.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.