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

 

When I run the following code (simplified from my original problem) I get the following error message : 

     ERROR: Required operator not found in expression: find("apple", "a")
     ERROR: The macro TEST will stop executing.

Is there any reason I cannot use the %eval on the find function?

 

%macro test();
%let a=apple;
%let b=a;
%let c=%eval(find("&a", "&b"));
%put &c;
%mend test;
%test(); 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

%EVAL() is for integer calculations primarily or condition checks. For functions you want %SYSFUNC() which you need to wrap around each SAS function to differentiate it from text. 

 

You can use %SYSEVALF() to do decimal math.

 


@saras wrote:

 

When I run the following code (simplified from my original problem) I get the following error message : 

     ERROR: Required operator not found in expression: find("apple", "a")
     ERROR: The macro TEST will stop executing.

Is there any reason I cannot use the %eval on the find function?

 

%macro test();
%let a=apple;
%let b=a;
%let c=%eval(find("&a", "&b"));
%put &c;
%mend test;
%test(); 


 

View solution in original post

4 REPLIES 4
Reeza
Super User

%EVAL() is for integer calculations primarily or condition checks. For functions you want %SYSFUNC() which you need to wrap around each SAS function to differentiate it from text. 

 

You can use %SYSEVALF() to do decimal math.

 


@saras wrote:

 

When I run the following code (simplified from my original problem) I get the following error message : 

     ERROR: Required operator not found in expression: find("apple", "a")
     ERROR: The macro TEST will stop executing.

Is there any reason I cannot use the %eval on the find function?

 

%macro test();
%let a=apple;
%let b=a;
%let c=%eval(find("&a", "&b"));
%put &c;
%mend test;
%test(); 


 

ChrisNZ
Tourmaline | Level 20

%EVAL() is for integer calculations primarily or condition checks. For functions you want %SYSFUNC() which you need to wrap around each SAS function to differentiate it from text. 

 

You can use %SYSEVALF() to do decimal math.

Additionally,

%eval (and %sysevalf) can be used for boolean evaluations.

%sysevalf can interpret SAS dates strings correctly.

 

%put => %eval(%sysfunc(findw(bb ba,ba))>0); 
%put => %sysevalf('01jan1990'd); 

=> 1
=> 10958

 

 

 

ballardw
Super User

When running strictly macro code as you are the values of variables should seldom be inside quotes at all:

 

%macro test();
%let a=apple;
%let b=a;
%let c=%sysfunc(find("&a", "&b"));
%put Test value of c is &c;
%mend test;
%test(); 

%macro test2();
%let a=apple;
%let b=a;
%let c=%sysfunc(find(&a, &b));
%put Test2 value of c is &c;
%mend test2;

%test()
%test2()
FreelanceReinh
Jade | Level 19

Also, if there's a suitable macro function, you don't need to call a DATA step function:

%let c=%index(&a, &b);

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1391 views
  • 7 likes
  • 5 in conversation