data rawsql_1 rawsql_2(keep=date nclose);
set rawsql;
by stockcode nw date;
retain flag_high s_wk lwboll l2wboll lwnclose l2wnclose initial s_week;
/*HIGHLIMIT check*/
if first.stockcode then do;
flag_high=' ';
s_wk=.;
end;
if highlimit='Y' then do;
flag_high='Y';
s_wk=nw;
end;
if s_wk^=. then do;
if nw>s_wk+7 then do;
flag_high=' ';
s_wk=.;
end;
end;
/*WBOLL check*/
if last.nw then do;
lwboll=wboll;
l2wboll=lag(wboll);
lwnclose=nclose;
l2wnclose=lag(nclose);
end;
if (.<input(lwboll,best.)<lwnclose) & (.<input(l2wboll,best.)<l2wnclose) & (lwnclose<l2wnclose)
then flag_wboll='Y';
/*3WEEK check*/
if ^missing(nclose)& ^missing(wboll) then daydif=nclose-input(wboll,best.);
if first.stockcode then do;
initial=0;
flag_3week=' ';
s_week=.;
end;
if .<daydif<0 & .<lag(daydif)<0 then do;
s_week=max(s_week,nw);
if initial=0 then do;
flag_3week='Y';
initial=1;
end;
end;
if ^missing(s_week) then do;
if nw>s_week+2 then initial=0;
end;
drop s_wk lwboll l2wboll lwnclose l2wnclose initial s_week daydif;
run;
data sqlx;
set rawsql_1;
set rawsql_2(firstobs=21 rename=(date=nf20date nclose=nf20close));
if date>='1Jan2021'd & flag_high='Y' & flag_wboll='Y' & flag_3week='Y';
drop nw flag:;
run;


雷达卡








谢谢大神[em17]
京公网安备 11010802022788号







