09-29-2015 05:32 AM
I've a code like below,
if %eval(&end_title)+%eval(&end_title1<_n_<%eval(&end_title)+%eval(&end_title1)+%eval(&end_title2) then do; put option;end
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: 1558<_n_<1558+1558+1558
Could someone tell me how to sum using %eval?
09-29-2015 05:48 AM
Why do you need to add so many evals? the logic function should work on the same way without it. Even though, if you want to add the %eval function, if macro variables END_TITLE, END_TITLE1 and END_TITLE2 are numeric should work.
if %eval(&end_title +&end_title1) < _n_ < %eval(&end_title+&end_title1+&end_title2) then do; put option;end
In words, what do you want to do with this condition?
09-29-2015 06:05 AM
Your mixing boolean logic &end_title1 < _n_ < ..., with numerical operations %eval(). Again, as per several other posts, why are you trying to do all this in macro language. Your clearly trying to force programming through macro. Step back and just write base SAS code to do what you want. If you see repeats of code, then put that in a macro, but don't try to program everything in macro code its crazy.
09-29-2015 10:59 AM
As others have mentioned, your code is unusual. It is rare to use the %EVAL macro function on a data step IF statement. %EVAL is for doing integer arithmetic in the macro language. The DATA step language does not need it.
That said, I'm surprised you are getting an error message. The below sample code "works". It is possible you have some unprintable characters in your actual example, or even decimal points. Second DATA step shows that %EVAL is not needed in this setting.
%let end_title=1; %let end_title1=2; %let end_title2=3; data _null_; set sashelp.class; if %eval(&end_title +&end_title1) < _n_ < %eval(&end_title+&end_title1+&end_title2) then do; put _n_=; end; run; data _null_; set sashelp.class; if (&end_title +&end_title1) < _n_ < (&end_title+&end_title1+&end_title2) then do; put _n_=; end; run;
09-29-2015 07:44 PM
You need to show more of the context of your program.
If you are working in a DATA step, all the %EVALs can go. The DATA step never uses them.
If you are not working in a DATA step, _N_ does not exist.
In either case, adding parentheses might help clarify your intention.