Monday, November 16, 2009

Logical expression play differently between %eval and DATA step

When programming macro, It is helpful to complete it in a DATA step and then port the code to macro. However, not all tricks in DATA step work in macro world.

Below is one tip for that:

data _null_;
do a=1 to 4;
if 1 < a < 3 then put a= "is between 1 and 3";
end;
run;

%macro test();
%put Wrong example:;
%do a=1 %to 4;
%if %eval(1 < &a < 3) %then
%put a=&a is between 1 and 3;
%end;

%put Correct example:;
%do a=1 %to 4;
%if %eval(1 < &a and &a < 3) %then
%put a=&a is between 1 and 3;
%end;
%mend;

%test()

No comments: