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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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