Help using Base SAS procedures

How to replace missing value using values in the previous line?

Reply
Frequent Contributor
Posts: 128

How to replace missing value using values in the previous line?

Hello everyone,

I want to ask how to use values in the previous line to replace the missing value?
Any help? I try:

if missing(a) then a=lag(a);

but this does not work.

Thank you! and Wait online!


-----------Before--------------
a b c

1 2 3
. . .
. . .
2 3 4
. . .
. . .
. . .
. . .
3 5 6
. . .
----------After------------

a b c

1 2 3
1 2 3
1 2 3
2 3 4
2 3 4
2 3 4
2 3 4
2 3 4
3 5 6
3 5 6

--------------------------
Super Contributor
Super Contributor
Posts: 3,174

Re: How to replace missing value using values in the previous line?

Perform the lag function assignment for each observation, creating:

l_a = lag(a);

then do you conditional assignment / override when the missing condition occurs.

Scott Barry
SBBWorks, Inc.
New Contributor
Posts: 2

Re: How to replace missing value using values in the previous line?

or use:

a=coalesce(a,lag(a));
Ask a Question
Discussion stats
  • 2 replies
  • 100 views
  • 0 likes
  • 3 in conversation