DATA Step, Macro, Functions and more

Macro var value with *, how to handle?

Accepted Solution Solved
Reply
Contributor
Posts: 50
Accepted Solution

Macro var value with *, how to handle?

I have the following code segment:

%let alist=a.*;

%let blist=b.*;

%if (&alist=a.*) and (&blist=b.*) %then %do;

ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:


       (&alist=a.*) and (&blist=b.*)

Basically it is the * that caused the error. I would like to compare if alist value equal to a.* and blist value equal to b.*, how to achieve this without error?


Accepted Solutions
Solution
‎11-07-2014 05:00 AM
Super Contributor
Posts: 305

Re: Macro var value with *, how to handle?

Hello,

%macro a;

%let alist=a.*;
%let blist=b.*;

%if (%bquote(&alist)=%str(a.*)) and (%bquote(&blist)=%str(b.*)) %then %do;
%put TRUE;
%end;


%mend a;

%a

View solution in original post


All Replies
Super User
Posts: 3,112

Re: Macro var value with *, how to handle?

One way is using %quote:

%if (%quote(&alist)=a.*) and (%quote(&blist)=b.*) %then %do;

SAS Employee
Posts: 340

Re: Macro var value with *, how to handle?

I think you also need %quote() or %str() around the left side of = sign.

Solution
‎11-07-2014 05:00 AM
Super Contributor
Posts: 305

Re: Macro var value with *, how to handle?

Hello,

%macro a;

%let alist=a.*;
%let blist=b.*;

%if (%bquote(&alist)=%str(a.*)) and (%bquote(&blist)=%str(b.*)) %then %do;
%put TRUE;
%end;


%mend a;

%a

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 190 views
  • 6 likes
  • 4 in conversation