data have;
infile cards dlm=',' truncover;
input treatment year x;
cards;
1,1980,0
1,1981,0
1,1982,0
1,1983,0
1,1984,5
1,1985,7
1,1986,0
1,1987,6
1,1988,2
1,1989,1
2,1980,0
2,1981,0
2,1982,0
2,1983,3
2,1984,4
2,1985,6
2,1986,0
2,1987,7
2,1988,3
2,1989,2
2,1990,1
2,1991,1
;
run;
data want;
set have;
by treatment;
retain found ;
lag_x=lag(x);
lag2_x=lag2(x);
if first.treatment then do;found=0;count=0;end;
if x ne 0 then found=1;
if found then count+1;
if count ge 3 then std3=std(x,lag_x,lag2_x);
drop lag:;
run;
... View more