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
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.