Try below code: %let name_list =aa bb cc dd;
%macro loop();
data xxx2;
set xxx;
w = 0;
s = 0;
p = 0;
%let i=1;
%do %while (%scan(&name_list, &i) ne );
%let next_name = %scan(&name_list, &i);
if substr(&next_name.,1,1) = 'w' then w = w + c&i.;
else if substr(&next_name.,1,1) = 's' then s = s + c&i.;
else if substr(&next_name.,1,1) = 'p' then p = p + c&i.;
%let i = %eval(&i + 1);
%end;
run;
%mend;
%loop(); If the variables your using to identify each material are easy to loop through (i.e. mat1,mat2,mat3.......) then the above can be simplified. Regards, Andy
... View more