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);
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.