@t75wez1 :
This suggested output totally defies your verbal description in the original post. To wit, it's not "by subject and test" but merely by FLAG1.
Anyway, this should work:
data have ;
input subjid lbtestcd $ lbdy flag1 $ ;
cards ;
101 alt 1 e
101 alt 2 .
101 alt 3 e
101 alt 4 e
101 ast 1 e
101 ast 3 e
101 ast 4 .
101 ast 5 e
102 alt 1 e
102 alt 2 .
102 alt 3 e
102 alt 4 e
102 ast 1 e
102 ast 3 e
102 ast 4 .
102 ast 5 e
102 ast 6 e
run ;
data want ;
do _n_ = 1 by 1 until (last.flag1) ;
set have ;
by flag1 notsorted ;
newflag = sum (newflag, 1) ;
end ;
if cmiss (flag1) or _n_ < 2 then newflag = 0 ;
do _n_ = 1 to _n_ ;
set have ;
output ;
end ;
run ;
Apropos, I see no I/O logic vis-a-vis setting the NEWFLAG to 0 or blank (do you mean a missing value by that? kind of odd since the variable is numeric). Hence, whenever it's "non-consecutive", the code above sets it to 0.
Kind regards
Paul D.
... View more