Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to evaluate a macro value containing ' - ' with %IF function.?

Status
Not open for further replies.

6656

Programmer
Nov 5, 2002
104
US
Hi, Anyone know How to evaluate a macro value containing
' - ' with %IF function.? %quote, %str, %bquote, ... can't mask the '-' with %if expression.

e.g.

%macro test;
...
%let mcrvar= abc-xyz;
%if %quote(&mcrvar) = abc-xye %then..... %else....
...
%mend;

Thanks,
Mike
 
I am not sure the need for macor quoting in your example.

Here is what I tested:

%macro test;
%let myvar = 1-2;
%if &myvar = 1-2 %then %put Yes! myvar = &myvar;
%else %put No! myvar = &myvar;
%mend test;

%test;

I got:

Yes! myvar = 1-2

Am I missing anything here?
 
Thanks Telalearner, If you use a charactor string instead of numeric charactor, you'll get error.
Anyway, I have a solution now. To get workaround, use %str() or %quote() on right side of equal sign.
e.g. %if %quote(&x)=%str(abc-xyz) %then........
 
%str masks special characters and mnemonic operators in constant text at macro compilation.
%quote masks special characters and mnemonic operators in a resolved value at macro executin.

In your case, the right side and = sign is a constant, using %str or %quote will not make a difference.

If it is also a macro variable, it will make a difference.

Try:
%let myvar = abc-xyz;
%let yourvar = abc-xyz;

%if %quote(&myvar) = %quote(&yourvar) %then ... will work.
%if %str(&myvar) = %str(&yourvar) %then ... will not work.

But if you use macro quote in the %let statement:
%let myvar = %str(abc-xyz);
%let yourvar = %str(abc-xyz);
%if &myvar = &yourvar %then...
or
%let myvar = %quote(abc-xyz);
%let yourvar = %quote(abc-xyz);
%if &myvar = &yourvar %then...

Both will work.




 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top