A nice home work 🙂
data have;
input Id $ xyz;
datalines;
A 1
A 2
A 3
A 4
B 1
B 2
B 3
B 4
;
data want;
do _n_=1 by 1 until(last.id);
set have;
by id;
if _n_=2 then _t=xyz;
else if _n_=4 then xyz=_t;
output;
end;
drop _:;
run;
Or since you desire traditional retain statement method, here you go:
data want;
set have;
by id;
retain _t;
if first.id then n=0;
n+1;
if n=2 then _t=xyz;
else if n=4 then xyz=_t;
drop n _t;
run;
Please mark the appropriate response (not this one) as the correct answer so that we know your question is resolved.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.