data _null_;
source = "word1 word2 word3";
pos = findw(source, 'word1', ' ', 'i');
put "SUCCESS: " pos=;
run;
SUCCESS: pos=1
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
ERROR: %SYSEVALF function has no expression to evaluate.
%put FAIL: %sysfunc(findw(%str(word1 word2 word3), word1, %str( ), i));
FAIL: 1
%put SUCCESS: %sysfunc(findw(%str(word1 word2 word3), word1, ' ', i));
SUCCESS: 1
Wednesday, February 18, 2026
%SYSFUNC is not as smart as DATA step
Basically %SYSFUNC is for string manipulation. It is difficult for %SYSFUNC to know what argument is numeric or character. Take FINDW as example, if we do not specify character argument clearly, it will try converting the string to numeric using %SYSEVALF. Although it may give out correct value, it still give out ERROR message.
Subscribe to:
Comments (Atom)