DATA Step, Macro, Functions and more

Filling up and down missing values with non-missing values

Reply
Frequent Contributor
Posts: 127

Filling up and down missing values with non-missing values

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

Super User
Posts: 19,860

Re: Filling up and down missing values with non-missing values

What are the rules?

Frequent Contributor
Posts: 127

Re: Filling up and down missing values with non-missing values

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

 

Super User
Posts: 19,860

Re: Filling up and down missing values with non-missing values

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

Super User
Posts: 10,044

Re: Filling up and down missing values with non-missing values

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;
Frequent Contributor
Posts: 127

Re: Filling up and down missing values with non-missing values

Thanks a lot.  It helped...

Ask a Question
Discussion stats
  • 5 replies
  • 103 views
  • 0 likes
  • 3 in conversation