webgu 发表于 2013-8-15 15:18 
call execute也是我经常用的,挺好的一种处理方法。但是这里你要把原始数据集多n变,有几个不同ID就要读几遍。我下面给一个我也经常用到拼code的方法,只读一遍原数据集就可以了。
data have;
input id $ num;
datalines;
a 1
a 2
c 1
c 2
;
run;
proc sql noprint;
create table tmp as
select distinct id
from have;
select 'want_'||id into: dataname separated by ' '
from tmp;
quit;
%put &dataname.;
data Code1;
length code $100.;
code="data &dataname.; set have;";
run;
data Code2;
length code $100.;
set tmp;
if _n_=1 then code=cats('if ID="', ID, '" then output want_', ID, ';');
else code=cats('else if ID="', ID, '" then output want_', ID, ';');
keep code;
run;
data code3;
length code $100.;
code='run;';
run;
data Code;
length Code $100.;
set Code1-Code3;
file "Code.txt";
put Code $;
run;
%include "Code.txt";
好用的话,给钱加分~ 哈哈哈