Greetings! I'd like to sum a set of variables, the set of which are identified by a variable in the dataset. I realize there are many ways to do this, but ultimately I'll be processing large output from PROC MCMC where array statements are unwieldy. In the data set 'test' I identify the variable list to be summed by the first column labeled 'x', so that I will compute a_1+a_2+a_3 in the first row, then b_1+b_2+b_3 in the second row, etc. data in;
input x $ a_1 a_2 a_3 b_1 b_2 b_3 c_1 c_2 c_3;
datalines;
a 1 1 1 2 2 2 3 3 3
b 1 1 1 2 2 2 3 3 3
c 1 1 1 2 2 2 3 3 3
;
run; The macro %vTest writes out the summation: %macro vtest(xVal);
0 %do i = 1 %to 3; +&xVal._&i. %end;
%mend vtest; data set 'test_data' reads dataset 'in' and processes using the RESOLVE function and %vtest. Results are then printed. data test_data;
set in;
rc = resolve(cats('%vtest(',x,')'));
run;
options nocenter;
proc print data= test_data noobs;
run; As you can see, the column rc shows 0+a_1+a_2+a_3. I'd like rc to show the actual sum, i.e. 3, 6, and 9. Many thanks in advance! Garnett
... View more