Define both z1 and z2 as group, calculate sums for groups defined by z1, and the compute the percentages:
data have;
input z1 $ z2 x w;
cards;
A 1 10 20
A 2 20 30
A 3 40 50
B 1 15 30
B 2 25 30
B 3 40 50
;
proc report data=have;
column z1 z2 x pct_x w pct_w;
define z1 / group;
define z2 / group;
define x / analysis;
define pct_x / computed format=percent8.2;
define w / analysis;
define pct_w / computed format=percent8.2;
compute before z1;
x_sum = x.sum;
w_sum = w.sum;
endcomp;
compute pct_x;
pct_x = x.sum / x_sum;
endcomp;
compute pct_w;
pct_w = w.sum / w_sum;
endcomp;
run;
Result:
z1 z2 x pct_x w pct_w
A 1 10 14.29% 20 20.00%
2 20 28.57% 30 30.00%
3 40 57.14% 50 50.00%
B 1 15 18.75% 30 27.27%
2 25 31.25% 30 27.27%
3 40 50.00% 50 45.45%
... View more