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();
%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();
%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();
%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
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()
Also, if there's a suitable macro function, you don't need to call a DATA step function:
%let c=%index(&a, &b);
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.