Hi,
I have a macro "isIn" which is supposed to test if an element is in a given (macro) string.
The code is as follows :
%macro rank(string,element,sep=);
/* Returns element's index in a list of elements */
%if &sep ne %then %do;
%sysfunc(findw(&chaine.,&element.,&sep,E))
%end;
%else %do;
%sysfunc(find(&chaine.,&element.))
%end;
%mend;
%macro isIn(string,element);
/* Tests whether an element is in a given string */
%eval(%rank(&string.,&element.,sep=' ')>0)
%mend;
Somewhere in the program, &mystring. is initialized to "U Z E" (without the quotes) and elsewhere the following test occur :
%if %isIn(&mystring,U) %then ...
The test is expected to return 1 since "U" is in "U Z E".
Several execution of the program give different results for the above test, yet the input is always the same.
It shoudn't be too complicated to modify the code and avoid using the findw function but I am just wondering
what is wrong exactly and why the macro behavior seems random.
Do you see anything wrong with the above code ?
We use SAS 9.4.
Thanks
... View more