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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.