2017-12-18 213 views

回答

3

使用逐元素乘法運算,#在IML:

proc iml; 
a = {1 2 3}; 
b = {2 3 4, 
    1 5 3, 
    5 9 10}; 

c = a#b; 
print c; 
quit; 
+0

對於所有在SAS/IML倍增,看到「方式在SAS/IML語言來倍增」在https://blogs.sas.com/content/iml/2013/05方式的解釋/20/matri-multiplication.html – Rick

0

有當然的非IML解決方案,或二十,雖然IML以DOM指出是可能比較容易。這裏有兩個。

首先,將它們置於一個數據集上,其中a數據集位於每行(帶有一些其他變量名稱) - 見下文。然後,或者只是做數學(使用數組)或使用PROC MEANS或類似的數據集來使用a作爲權重。

data a; 
    input w_x w_y w_z; 
    datalines; 
1 2 3 
;;;; 
run; 

data b; 
    input x y z; 
    id=_n_; 
    datalines; 
2 3 4 
1 5 3 
5 9 10 
;;;; 
run; 

data b_a; 
    if _n_=1 then set a; 
    set b; 
    *you could just multiply things here if you wanted; 
run; 


proc means data=b_a; 
class id; 
types id; 
var x/weight=w_x; 
var y/weight=w_y; 
var z/weight=w_z; 
output out=want sum=; 
run; 
相關問題