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;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.