@ArseneWenger My humble suggestion is to proceed with @ballardw simple yet neat approach with one pass and done and that is pretty much what all of us would. But here you go, just for your needs, have fun.- Nonetheless, I would never do this for my work data try; input id status; datalines; 1 8 1 . 1 1 1 . 2 8 2 . 2 . 2 . 3 1 3 . 3 8 3 . 4 . 4 . 4 . 5 . 5 . 5 8 5 . ; run; data want; if _N_ = 1 then do; declare hash h(dataset: 'try', ordered: 'yes',multidata:'yes'); declare hiter iter('h'); h.defineKey('id'); h.defineData('id','status'); h.defineDone(); call missing(id, status); end; rc = iter.first(); do while (rc = 0); if lag(id) ne id then tag=0; if status=8 then tag=1; else if status=1 then tag=0; output; rc = iter.next(); end; drop rc; run;
... View more