waitalone11 发表于 2010-2-3 09:36 
如果是在同一个DATA步里实现的话该怎么写程序?谢谢!
But you will have to read twice, one for calculating a total and the other for calculating a percent.
Here it is. This sort of programming style is posted several times.There are some good knowledge points here.
data a;
input a $ b;
cards;
a 1
b 2
c 3
d 4
;
run;
data b;
do _n_=1 to nobs;
set a nobs=nobs;
tot_b+b;
end;
do _n_=1 to nobs;
set a ;
pct=b/tot_b;
output;
end;
run;
proc print; run;
proc sql;
select *, b/sum(b) as pct
from a;
quit;