data a;
input dt_jzr cagr rtn;
cards;
19911231 10 20
19921231 15 -10
19931231 20 20
19941231 25 -10
19951231 30 -20
19961231 35 20
19971231 40 20
19981231 45 20
19991231 50 -10
20001231 55 20
20011231 60 10
20021231 65 20
20031231 70 20
20041231 75 20
;
run;
data a;
set a;
stocl_code="000001";
stock_name="深发展A";
output;
stocl_code="000002";
stock_name="BBBBBB";
output;
run;
proc sort data=a;by stocl_code dt_jzr;run;
data b;
set a;
by stocl_code dt_jzr;
if first.stocl_code then seq=1;
else seq+1;
if rtn>0 then grp=1;else grp=0;
n1=lag(grp);
n2=lag2(grp);
n3=lag3(grp);
total= grp+n1+n2+n3;
if seq<=3 then total=.;
if cagr>30 and total>=2 then output;
run;

供参考