BookmarkSubscribeRSS Feed
pp2014
Fluorite | Level 6

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

5 REPLIES 5
pp2014
Fluorite | Level 6

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

 

Reeza
Super User

I'm sorry, that's not clear to me. Hopefully someone else understands your question.

Ksharp
Super User
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;
pp2014
Fluorite | Level 6

Thanks a lot.  It helped...

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

Register now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 2354 views
  • 0 likes
  • 3 in conversation