2015-10-30 101 views
3

我寫的代碼,以顯示與PROC報告下列記錄。我想用紅色突出顯示每行的最大數量。我已經嘗試了代碼,但突出顯示了不同的值。請在下面的代碼中提供更正,以顯示正確突出顯示的值。SAS PROC報表樣式

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; 

回答

2

據我所知,如果您使用計算語句,順序是重要的。所以,如果你使用的計算A1,A1僅具有當時的值,計算A2意味着只有A1和A2有一個值,等等...

所以,你必須使用你的最後一列的計算陳述,那麼所有的列都有值,結果應該沒問題。

找到此上Sas page

注意:所計算的變量的位置是重要的。從左至右在一份報告中的一排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

+0

非常感謝... –