2016-02-24 59 views
1

(交叉貼在SAS Communities site)的跨接變量值獲得在PROC報告

我很感興趣,用我的電話的URL一家橫跨變量的值在COMPUTE語句定義語句。

在下面的例子中,PROC REPORT可以讓我訪問每個TYPES變量值的值......當列正在構建時,這樣我可以在URL鏈接中包含該值?我可以使用N變量訪問COMPUTE語句中的值嗎?

options missing=""; 
data REPORT; 
input VARIABLE $ TYPES $; 
datalines; 
VAR1 TYPE1 
VAR1 TYPE2 
VAR1 TYPE3 
VAR1 TYPE5 
; 
PROC FORMAT ; 
VALUE $TYPE 
'TYPE1'='Type 1' 
'TYPE2'='Type 2' 
'TYPE3'='Type 3' 
'TYPE4'='Type 4' 
'TYPE5'='Type 5'; 
Run ; 
proc report data=REPORT nowd; 
column ("Variables" variable) ("TYPES" types,n); 
define variable/''; 
define types/across '' format=$type. preloadfmt; 
define n/'' format=comma12.; 
compute types; 
    If _c2_>0 then 
    call define("_c2_","style","style={url = '<MY URL>'); 
endcomp; 
run; 

回答

1

您可以訪問單個的價值,你構建了方式:

proc report data=REPORT nowd; 
column ("Variables" variable) ("TYPES" types,n); 
define variable/''; 
define types/across '' format=$type. preloadfmt; 
define n/'' format=comma12.; 
compute types; 
    If _c2_>0 then 
    call define("_c2_","style",cats("style={url = '",_C2_,"'")); 
endcomp; 
run; 

您不能訪問當然行級值,因爲整個變量不這樣工作。

或者,如果你想獲得「2型」等爲名義,我想你會走這條路(使用的格式,並且COL而不是「C2」)。我不認爲有一種方法可以直接訪問跨價值本身。

由於你大概是通過使用宏來單獨構建這些計算塊,所以我可能會避開格式並直接將該變量的值直接傳遞給宏。如果不是,那麼格式可能會有用。

PROC FORMAT ; 
VALUE $TYPE 
'TYPE1'='Type 1' 
'TYPE2'='Type 2' 
'TYPE3'='Type 3' 
'TYPE4'='Type 4' 
'TYPE5'='Type 5'; 
value NType 
1='Type 1' 
2='Type 2' 
3='Type 3' 
4='Type 4' 
5='Type 5'; 
Run ; 
proc report data=REPORT nowd; 
column ("Variables" variable) ("TYPES" types,n); 
define variable/''; 
define types/across '' format=$type. preloadfmt; 
define n/'' format=comma12.; 
compute types; 
    If _c2_>0 then 
    call define(_COL_,"style",cats("style={url = '",put(_COL_,NType.),"'")); 
endcomp; 
run; 
+0

我相信你是對的。我的問題的答案是我無法得到跨變量的值...但我認爲你的代碼使我找到了一個解決方案。謝謝。 –