I have following data:
data have;
input id $2. tr1 $4. tr2 $4.;
cards;
12 AB4D
12 AB4D MN2X
13 AB4D MN2X
13 MN2X
14 AB4D MN2X
14 AB4D MN2X
run;
I want the output as follows:
ID t r1 tr2
12 AB4D MN2X
12 AB4D MN2X
13 AB4D MN2X
13 AB4D MN2X
14 AB4D MN2X
14 AB4D MN2X
Can anybody help me in getting the missing values filled using SAS?
Thanks
What are the rules?
Sometimes particular ID may have missing tr2 Value and have only tr1 value. In that case keep only tr1 value and leave tr2 blank
for example
15 AB4D
15 AB4D
I'm sorry, that's not clear to me. Hopefully someone else understands your question.
data have;
input id tr1 $ tr2 $;
cards;
12 AB4D .
12 AB4D MN2X
13 AB4D MN2X
13 . MN2X
14 AB4D MN2X
14 AB4D MN2X
;
run;
data temp1;
set have;
by id;
if first.id then n=0;
n+1;
run;
data temp2;
update temp1(obs=0) temp1;
by id;
output;
run;
proc sort data=temp2;
by id descending n;
run;
data want;
update temp2(obs=0) temp2;
by id;
output;
run;
Thanks a lot. It helped...
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.