SAS 宏 if then else always ELSE

SAS macro if then else always ELSE

在制作一些热图的过程中,我遇到了一些问题。我所有的细胞都涂上了黄色! MLOGIC 显示所有语句都为黄色,但单元格中的值不同?有红色和白色。你能告诉我我的错误吗?谢谢!下面的代码和日志:

%macro main;

ods html body='temp.html';

proc report data=step3 nowd;
column  kri_id range_mid_1 range_mid_2 
%do i=1 %to 9;
a2017_M0&i. %end;
;
define kri_id / display;
define range_mid_1 / display;
define range_mid_2 / display;
%do i=1 %to 9;
define a2017_M0&i. / display;
%end;
%do p=1 %to 9;
compute a2017_M0&p.;
     %if a2017_M0&p. > range_mid_2
     %then call define(_col_, "style", "STYLE=[background=red]");

%else %if  range_mid_1 < a2017_M0&p. < range_mid_2
     %then call define(_col_, "style", "STYLE=[background=yellow]");
     ;endcomp;
%end;
;run;

ods html close;
ods html body='temp.html';
%mend; %main;

日志文件如下

SYMBOLGEN:  Macro variable P resolves to 1
MLOGIC(MAIN):  %IF condition a2017_M0&p. > range_mid_2 is FALSE
SYMBOLGEN:  Macro variable P resolves to 1
MLOGIC(MAIN):  %IF condition range_mid_1 < a2017_M0&p. < range_mid_2 is TRUE
MPRINT(MAIN):   call define(_col_, "style", "STYLE=[background=yellow]") ;
MPRINT(MAIN):  endcomp;
MLOGIC(MAIN):  %DO loop index variable P is now 2; loop will iterate again.
SYMBOLGEN:  Macro variable P resolves to 2
MPRINT(MAIN):   compute a2017_M02;
SYMBOLGEN:  Macro variable P resolves to 2
MLOGIC(MAIN):  %IF condition a2017_M0&p. > range_mid_2 is FALSE
SYMBOLGEN:  Macro variable P resolves to 2
MLOGIC(MAIN):  %IF condition range_mid_1 < a2017_M0&p. < range_mid_2 is TRUE
MPRINT(MAIN):   call define(_col_, "style", "STYLE=[background=yellow]") ;
MPRINT(MAIN):  endcomp;
MLOGIC(MAIN):  %DO loop index variable P is now 3; loop will iterate again.
SYMBOLGEN:  Macro variable P resolves to 3
MPRINT(MAIN):   compute a2017_M03;
SYMBOLGEN:  Macro variable P resolves to 3
MLOGIC(MAIN):  %IF condition a2017_M0&p. > range_mid_2 is FALSE
SYMBOLGEN:  Macro variable P resolves to 3

和ETC

您在需要实际 SAS 代码逻辑的地方使用宏逻辑。

你总是得到 %ELSE 子句的原因是因为字母 a 小于字母 r 所以这个测试总是错误的。

%if a2017_M0&p. > range_mid_2

对于宏处理器来说,a2017_M01range_mid_2 只是文本字符串。宏处理器对您的数据集变量一无所知。

谢谢!在您的帮助下,我在这里找到了答案。我不得不使用没有 % 的 IF THE ELSE。比它比较变量