Each sas table observation (row) has the same number of columns (ID and max number of branches).
I suppose yourinput is probaly excel iported into sas. In such case all tyepes have the same number of barnches, either branch1, branch2 or barnch(n). Ii is possible that the value of a specific type,branch(x) is missing. Remember that the sum result of values, where one of them (or more) is missing - the result is also missing value.
Suppose there are maximum N branches in the input, that is the variables are: M1_branch1, M1_branch2, ..., M1_cranchN and M2_branch1, M2_branch2, ..., M2_cranchN. In such case the simplest code will be:
%let N=4; /* maxno of barnches */
data want;
set have;
array m1 {*} M1_branch1 - M1_branch&N;
array m2 {*} M2_branch1 - M2_branch&N;
do i=1 to &N;
m1(i) = m1(i) + m2(i);
end;
keep type M1_branch1 - M1_branch&N;
run;
... View more