Replace missing value with a non-missing in the column

Reply
Contributor sfo
Contributor
Posts: 66

Replace missing value with a non-missing in the column

Hi,

I have a dataset like this:

ID A B

1  10 .

2  .   20

and I would want to replace the missing in the columns by the non-missing number in that column i.e. have a result like this:

ID A B

1  10  20

2  10   20

I tried cumulative but it gives the result in row 2 for ID = 2. Is there a way I can achieve the above result?

Thanks

Trusted Advisor
Posts: 1,204

Re: Replace missing value with a non-missing in the column

data want;

set have;

a=coalesce(a,b);

b=coalesce(b,a);

run;

Contributor sfo
Contributor
Posts: 66

Re: Replace missing value with a non-missing in the column

Thanks. I tried that and I am getting the following:

ID A B

1  10  10

2  20   20

But I need this:

ID A B

1  10  20

2  10   20

Can this be generated?

Trusted Advisor
Posts: 1,204

Re: Replace missing value with a non-missing in the column

My bad just not understood correctly, please try this one.

proc stdize data=have out=want reponly method=mean;

var a b;

run;

proc print data=want;

run;

Contributor sfo
Contributor
Posts: 66

Re: Replace missing value with a non-missing in the column

Thanks it worked. I was not aware of this procedure.

Ask a Question
Discussion stats
  • 4 replies
  • 197 views
  • 3 likes
  • 2 in conversation