SAS Proc report风格

3

我正在编写一个用proc report显示以下记录的代码。我想用红色高亮显示每行中的最大值。我已经尝试了代码,但它高亮显示了不同的值。请提供以下代码的更正以正确显示高亮值。

    data records;
    input a1 a2 a3 a4 a5;
    cards;
    37 95 80 52 85 
    94 .  7  10 14 
    64 5  71 14 92 
    .  55 38 .  46 
    ;
    run;

    proc report data=records nowd;
    column a1 a2 a3 a4 a5;
    define a1/display;
    define a2/display;
    define a3/display;
    define a4/display;
    define a5/display;

    compute a1;
    if a1=Max(a1,a2,a3,a4,a5) then call define('a1','style','style={foreground=white background=red}');
    endcomp;
    compute a2;
    if a2=Max(a1,a2,a3,a4,a5) then call define('a2','style','style={foreground=white background=red}');
    endcomp;
    compute a3;
    if a3=max(a1,a2,a3,a4,a5) then call define('a3','style','style={foreground=white background=red}');
    endcomp;
    compute a4;
    if a4=max(a1,a2,a3,a4,a5) then call define('a4','style','style={foreground=white background=red}');
    endcomp; 
    compute a5;
    if a5=max(a1,a2,a3,a4,a5) then call define('a5','style','style={foreground=white background=red}');
    endcomp; 
    run;
1个回答

2
据我所知,如果使用compute语句,顺序很重要。因此,如果使用compute a1,则此时只有a1具有值,使用compute a2意味着只有a1和a2具有值,依此类推...
因此,您必须使用最后一列进行计算语句,这样所有列都有值,结果应该是正确的。
Sas页面上找到了以下内容:
引用: 注意:计算变量的位置很重要。PROC REPORT从左到右为报表中的行分配列值。因此,您不能基于出现在其右侧的任何变量来计算计算变量。
因此,请尝试按照以下方式操作,这对我有效:
proc report data=records nowd;
column a1 a2 a3 a4 a5;
define a1/display;
define a2/display;
define a3/display;
define a4/display;
define a5/display; 

compute a5;
if a1=Max(a1,a2,a3,a4,a5) then call define('a1','style','style={foreground=white background=red}');
if a2=Max(a1,a2,a3,a4,a5) then call define('a2','style','style={foreground=white background=red}');
if a3=max(a1,a2,a3,a4,a5) then call define('a3','style','style={foreground=white background=red}');
if a4=max(a1,a2,a3,a4,a5) then call define('a4','style','style={foreground=white background=red}');
if a5=max(a1,a2,a3,a4,a5) then call define('a5','style','style={foreground=white background=red}');
endcomp; 
run;

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接