【问题标题】:SAS macro if then else always ELSESAS 宏 if then else 总是 ELSE
【发布时间】:2018-03-22 17:16:12
【问题描述】:

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

%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

【问题讨论】:

  • 在计算块中使用常规 if then ekse

标签: sas sas-macro


【解决方案1】:

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

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

%if a2017_M0&p. > range_mid_2

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

【讨论】:

  • 汤姆谢谢你。小问题。如果数据集中的列数不总是 9?你现在是怎么解决的?
  • 找出您要运行的 SAS 代码并使用宏逻辑生成该程序。
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-20
    相关资源
    最近更新 更多