Hi,
I'm getting an error using following code. please help what am I missing ?
%let indir=//folder/path;
%PUT &indir;
%if %substr(&indir,%length(&indir),1)^=/ %then %let indir=&indir/;
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:
T^=/
It appears that the bare / character may be treated as expecting division (numeric)
See if forcing quotes does what you expect:
%if %quote(%substr(&indir,%length(&indir)))^= "/" %then %let indir=&indir/;
When the second parameter of Substr is the length of the variable you get the last character, so the ,1 isn't needed.
Something returned from your functions is coming back as character instead of numeric. You might try doing a STRIP for the data you're trying to get the length of.
Jim
It appears that the bare / character may be treated as expecting division (numeric)
See if forcing quotes does what you expect:
%if %quote(%substr(&indir,%length(&indir)))^= "/" %then %let indir=&indir/;
When the second parameter of Substr is the length of the variable you get the last character, so the ,1 isn't needed.
That cannot work. You are comparing a one character string to a three character string. They will never be equal.
Either add real quotes to both sides.
Or add macro quoting to both sides.
Beautiful. %quote() comes to the rescue! Thanks.
%EVAL() is looking for the numbers you want to divide. Macro quoting helps.
904 %if /=/ %then %do; ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: /=/ ERROR: Skipping to next %END statement. 905 %put equal; 906 %end; 907 %if %str(/)=%str(/) %then %do; 908 %put equal; equal 909 %end;
So add macro quoting on both sides of the operator.
%if %qsubstr(&indir,%length(&indir))^=%str(/) %then %let indir=&indir/;
My first try was not the issue. Try wrapping the left side of the equation in %BQUOTE.
This seems to be working for me:
%let indir=//folder/path;
%PUT &indir;
%if %bquote(%substr(&indir,%length(&indir),1)) ^= %bquote(/) %then
%DO;
%let indir=&indir/;
%END;
%else
%DO;
%put NOTE: No action taken;
%END;
Jim
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.