Hi ... just another thought on this. If the observations are not sorted in step order
within a CID, you could try the following. The first pass (first SET HAVE) finds the
largest value of STEP that is not 9. The second pass replaces the 9s with
that largest value from the first pass.
data need;
do until (last.cid);
set have (in=a where=(step ne 9)) have;
by cid;
if a then big = max(big,step);
if ^a then do; step = ifn(step ne 9, step, big); output; end;
end;
drop big;
run;
Based on ...
Interleaving a Dataset with Itself: How and Why
by Howard Schreier
data have; input CID $ STEP TCODE $; cards; 001 1 aa000 001 1 aa002 001 2 aa000 001 2 aa001 001 2 aa003 001 9 aa000 001 9 aa004 002 1 aa000 002 1 aa002 002 1 aa003 002 1 aa004 002 9 aa002 002 9 aa005 002 9 aa006 ;;;; run; data want(drop=_step); set have; retain _step; if step ne 9 then _step=step; else step=_step; run;
Ksharp
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.