Hello, I am working on a run test for many different stock indices covering many years. I got the code from SAS help yet it's only run for the whole data, but I need to do it for each year of each index. However, I cannot apply the BY index year in the following step. Please any help would be extremely appreciated. The following DATA step computes the total number of runs (RUNS), the number of positive values (NUMPOS), and the number of negative values (NUMNEG). data runcount;
set two nobs=nobs;
if d=0 then delete;
if d>0 then n+1;
if d<0 then m+1;
retain runs 0 numpos 0 numneg 0;
previous=lag(d);
if _n_=1 then do;
runs=1;
prevpos=.;
currpos=.;
prevneg=.;
currneg=.;
end;
else do;
prevpos=( previous > 0 );
currpos=( d > 0 );
prevneg=( previous < 0 );
currneg=( d < 0 );
if _n_=2 and (currpos and prevpos) then numpos+1;
else if _n_=2 and (currpos and prevneg) then numneg+1;
else if _n_=2 and (currneg and prevpos) then numpos+1;
else if _n_=2 and (currneg and prevneg) then numneg+1;
if currpos and prevneg then do;
runs+1;
numpos+1;
end;
if currneg and prevpos then do;
runs+1;
numneg+1;
end;
end;
run;
data runcount;
set runcount end=last;
if last;
run;
... View more