×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

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

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

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

(OP)
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

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

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?

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

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

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

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




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

(OP)
Thanks, A good summary.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close