I have a column with IDs that repeat, and I would like to translate the second column to repeat the first value for each unique ID. EXCEPT for when the value is NULL, the value needs to stay NULL. Below is an example of the column I have, and the column I want.
ID HAVE WANT
1 12 12
1 19 12
1 23 12
2 40 40
2 NULL NULL
2 25 40
3 NULL NULL
3 11 11
3 NULL NULL
4 24 24
4 NULL NULL
4 72 24
4 NULL NULL
Something like below should do.
data have;
input id have want;
datalines;
1 12 12
1 19 12
1 23 12
2 40 40
2 . .
2 25 40
3 . .
3 11 11
3 . .
4 24 24
4 . .
4 72 24
4 . .
;
data want(drop=_:);
set have;
by id;
retain _tmp;
if first.id then call missing(_tmp);
if not missing(have) then
do;
if missing(_tmp) then _tmp=have;
derived=_tmp;
end;
run;
proc print data=want;
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.