BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tlyang888
Calcite | Level 5


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!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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) ...

View solution in original post

5 REPLIES 5
Tom
Super User Tom
Super User

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) ...

Astounding
PROC Star

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.

Tom
Super User Tom
Super User

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

Quentin
Super User

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()
BASUG is hosting free webinars Next up: Jane Eslinger presenting PROC REPORT and the ODS EXCEL destination on Mar 27 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
tlyang888
Calcite | Level 5

Thank you all for those hints. It did answer my question. I did forget about some basics in macro.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1006 views
  • 3 likes
  • 4 in conversation