0

表格1

Age     B C D E F G H
0-10    5 6 8 9 0 1 1
10-20   4 5 9 7 1 4 5
20-30   5 6 5 4 2 5 8
0-10    0 4 0 5 8 0 7

表2

Age      A1  B1  C1  D1
0-10     0.1 0.9 0.2 
10-20    0.5 0.6 0.7

我要提取

SUMPRODUCT(Table1(G:H),Table2(B1:C1))

有条件的IF Table1.Age = Table2.Age

输出表应如下所示

AGE   SUMPRODUCT
0-10  0.8
10-20 0.70
4

1 回答 1

0

您需要将两个数据集合并在一起,然后计算产品的总和。

data want;
merge table1(in=a) table2(in=b);
by age;
if a and b;
newvar = sum(g*b1, h*c1);
run;

您可以在 SQL 连接或哈希表查找中做同样的事情。

数组:

data want;
merge table1(in=a) table2(in=b);
by age;
if a and b;
array avars[20] <list of a vars>;
array bvars[20] <list of b vars>;
do _t = 1 to dim(avars);
   newvar = sum(newvar,avars[_t]*bvars[_t]);
end;
run;
于 2013-08-22T11:55:20.067 回答