Hi Gocersah,
Arrays can be used but not directly. I give you an array solution as much as I understand your problem.
The steps are:
[1] Hold the values of ex1_1 ... ex1_4 in an array.
[2] Similarly, hold ex2_.., ex3_ in separate arrays.
[3] Hold sumex1, sumex2 and sumex3 in another array.
I used some fictional values for the cells of the arrays and computed p_m1, p_m2 and p_m3. I place the intermediate values computed from the arrays in the LOG.
data _null_;
array ex1[4] _temporary_ (10,20,30,40);
array ex2[4] _temporary_ (20,30,40,50);
array ex3[4] _temporary_ (30,40,50,60);
array sumex[3] _temporary_ (5,10,10);
do i = 1 to dim(ex1);
ex1[i] = ex1[i] / sumex[1];
ex2[i] = ex2[i] / sumex[2];
ex3[i] = ex3[i] / sumex[3];
put ex1[i] = ex2[i] = ex3[i] =;
end;
p_m1 = 0; p_m2 = 0; p_m3 = 0;
do i = 1 to dim(ex1);
p_m1 = p_m1 + ex1[i] * ex3[i];
p_m2 = p_m2 + ex1[i] * ex2[i];
p_m3 = p_m3 + ex2[i] * ex3[i];
end;
put p_m1 = p_m2 = p_m3= ;
run;
On the Log:
ex1[1]=2 ex2[1]=2 ex3[1]=3
ex1[2]=4 ex2[2]=3 ex3[2]=4
ex1[3]=6 ex2[3]=4 ex3[3]=5
ex1[4]=8 ex2[4]=5 ex3[4]=6
p_m1=100 p_m2=80 p_m3=68
The original values in the arrays ex1[ ], ex2[ ], ex3[ ] are modified in place by the appropriate division of sumx:
Then the product sums are simply the product of two parallel columns.
Best regards,
DATAsp
... View more