我写了下面的代码,但是为什么虽然没有报错,但是仍然没有结果。
主要是统计isbuy这个序列(这个序列是由0和1组成的)中,连续的0和连续的1这种串有多少个。要求是按照股票代码来统计的。
proc sort data=sh;by code date time;run;
data runcount;
set sh nobs=nobs end=last;
by code date;
prev=( lag(isbuy) = 0 );
curr=( isbuy = 0 );
if first.code=1 or first.date=1 then do;runs=0; numzero=0;end;
else do;
if curr and prev then do;numzero+1; end;
else if curr and ^prev then
do;
runs+1;
numzero+1;
end;
else if ^curr and prev then runs+1;
if last then
do;
numone=nobs-numzero;
n=nobs;
output;
end;
end;
keep code date runs numpos numneg n;
run;
数据在附件中。
谢谢!



雷达卡




京公网安备 11010802022788号







