I had thought about the retain statement which I use in the section
previous to the Lag section of my paper. In fact it is a better
solution than even using the Lag function in this case. However, I was
trying just to use the Lag function to accomplish the same task. I
guess perhaps there isn't one, possibly why I had trouble thinking of
From: Brian Shilling [mailto:email@example.com]
Sent: Tuesday, June 29, 2004 3:36 PM
To: Dunn, Toby
Subject: RE: Lag Question
Assuming that Z is temporary to get the values from the previous
could you use a retain statement? This works if you are going to
get rid of Z.
if x ne . then z = x;
else x = z;
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
Sent: Tuesday, June 29, 2004 4:15 PM
Subject: Lag Question
I am working a paper and have worked myself into question.
Say you have the following dataset:
input x y $1.;
and want to use the lag function to lag the value of variable (X) when
ever it is missing:
Easiest I figure is the following.
z = lag(x);
if x = . then x = z;
However, it gives a value of missing when there are two missing values
of x in a row:
Obs x y z
1 1 a .
2 2 a 1
3 2 a 2
4 4 a .
5 1 b 4
6 1 b 1
7 . b .
8 1 c .
9 2 c 1
10 1 d 2
Makes since, given how the queue works when using the Lag Function. Now
how would one use the Lag function and come up with value for the above
missing value and a value if there were more than one missing value for
x in a row?
For the life of me I can't come up with a workable solution if all I
have is the LAG function.