playmore 发表于 2012-12-3 16:41 
%do循环必须在宏里用,你用宏了吗?
用了。
%macro split_gain;
%do i=2 %to 32;
proc sql noprint;
select rep_gain_new into :rep_times
from Maxnum_gain_final;
where id_new=&i;
quit;
%do j=1 %to &rep_times;
data temp;set Repurchase_3;
where id_new=&i and rep_gain_new<=&j-1 and rep_gain_new ne .;run;
/*
proc sort data=temp;by descending date;run;
data temp;set temp;
tlag=date-lag(date);
retain t;
t+tlag;
run;
proc sort data=temp;by date;run;
data temp;set temp;
if t<-365 then delete;
if remark="证券买入" then delete;
run;
proc univariate data=temp noprint;
var gain;
by id_new;
output out=sum_sellgain sum=sell_gain;
run;
proc append base=sum_sellgain_all data=sum_sellgain force;run;
*/
%end;
%end;
%mend;
%split_gain;