请问如何简化以下code中的do循环累加语句(红色的code)?谢谢!
说明:该段code运行结果正确.
data gcb2;
set gcb1;
array food(9) food1-food9;
do i = 1 to 9;
*kindexc()是用于识别单个汉字的,
而indexc()是用于识别单个字节的(当用indexc()识别汉字时会生成错误的分类结果但log不会报错);
if kindexc(food(i),"菜","瓜","竹","柿","葱","蒜","卜","椒","冬","姜") then food(i)="蔬菜";
else if kindexc(food(i),"肉","骨","脚","腿","翅","鱼","尖") then food(i)="禽畜肉";
else if kindexc(food(i),"面","米","粉","包") then food(i)="粮谷类";
else if kindexc(food(i),"蛋") then food(i)="鸡蛋";
else if kindexc(food(i),"奶") then food(i)="牛奶";
else if kindexc(food(i),"油") then food(i)="植物油";
else if indexc(food(i),"盐") then food(i)="盐";
else if indexc(food(i),"抽") then food(i)="生抽";
end;
array effective(9) effective1-effective9;
do i = 1 to 9;
do j = 1 to 9;
if kindexc(food(i),"黄","大") then effective(j)=effective(j)*4;
end;
end;
do i = 1 to 9;
if kindexc(food(i),"黄","大","水","豆") then food(i)="豆腐";
end;
*ef= expected food,ef1-ef7依次为粮谷类、蔬菜、禽畜肉、鸡蛋、豆腐、牛奶、植物油,单位为“斤”;
ef1 = (n1*330 + n2*375 + n3*475)/500;
ef2 = (n1*450 + n2*475 + n3*500)/500;
ef3 = (n1*60 + n2*75 + n3*125)/500;
ef4 = (n1*1 + n2*1.5 + n3*1.5)*60/500;
ef5 = (n1*150 + n2*200 + n3*200)/500;
ef6 = (n1*150 + n2*150 + n3*150)/500;
ef7 = (n1*25 + n2*25 + n3*25)/500;
*af= actual food,af1-af9依次为粮谷类、蔬菜、禽畜肉、鸡蛋、豆腐、牛奶、植物油、盐、生抽,单位为“斤”;
do i = 1 to 9;
if food(i)="粮谷类" then do;
af1=0;
af1+effective(i);
end;
end;
do i = 1 to 9;
if food(i)="蔬菜" then do;
af2=0;
af2+effective(i);
end;
end;
do i = 1 to 9;
if food(i)="禽畜肉" then do;
af3=0;
af3+effective(i);
end;
end;
do i = 1 to 9;
if food(i)="鸡蛋" then do;
af4=0;
af4+effective(i);
end;
end;
do i = 1 to 9;
if food(i)="豆腐" then do;
af5=0;
af5+effective(i);
end;
end;
do i = 1 to 9;
if food(i)="牛奶" then do;
af6=0;
af6+effective(i);
end;
end;
do i = 1 to 9;
if food(i)="植物油" then do;
af7=0;
af7+effective(i);
end;
end;
do i = 1 to 9;
if food(i)="盐" then do;
af8=0;
af8+effective(i);
end;
end;
do i = 1 to 9;
if food(i)="生抽" then do;
af9=0;
af9+effective(i);
end;
end;
run;