|
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
it.
Toby Dunn
-----Original Message-----
From: Brian Shilling [mailto:bshilling@a-ci.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
records,
could you use a retain statement? This works if you are going to
eventually
get rid of Z.
data two;
set one;
retain z;
if x ne . then z = x;
else x = z;
run;
HTH
Brian
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
Dunn,
Toby
Sent: Tuesday, June 29, 2004 4:15 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Lag Question
I am working a paper and have worked myself into question.
Say you have the following dataset:
data one;
input x y $1.;
cards;
1 a
2 a
. a
4 a
1 b
. b
. b
1 c
2 c
1 d
;
run;
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.
data ccc;
set one;
z = lag(x);
if x = . then x = z;
run;
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.
TIA
Toby Dunn
|