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
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.