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...
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.