SAS宏如果那么其他总是ELSE

时间:2018-03-22 17:16:12

标签: sas sas-macro

在制作一些热图时,我遇到了一些问题。我所有的细胞都用黄色绘画! 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

2 个答案:

答案 0 :(得分:2)

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

您始终获得%ELSE子句的原因是因为字母a小于字母r所以此测试始终为false。

%if a2017_M0&p. > range_mid_2

宏处理器a2017_M01range_mid_2只是文本字符串。宏处理器对数据集变量一无所知。

答案 1 :(得分:0)

谢谢!在你的帮助下我找到了答案。我不得不使用IF THE ELSE而不是%。比它比较变量