2017-12-18 414 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; 
相关问题