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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

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
  • 4 replies
  • 746 views
  • 7 likes
  • 5 in conversation