|
... by the way: a RETAIN statement normally makes no sense for a dataset
variable. How does it work?
RETAIN prevents a variable to be set to missing at the end of the internal
loop. After that, all variables are loaded with the values of the next
obs. So you can prevent a variable from being initialized, anyway it gets
a new value from the new obs.
So define a new variable, not a existing one. This new variable you can
use to save a value.
data ...;
retain xx_dummy;
set ...;
if lag_xx ne . then do;
xx_dummy=lag_xx;
end;
else do;
lag_xx=xx_dummy; /* or whatever should be in there */
end;
...
run;
With that you fill up lag_xx with the previous value if it's missing.
However it is not clear to me, what you REALLY want to do. Is lag_xx
really needed? Or do you want to treat with XX and do something like the
above, maybe not only replace the missing, also add 30?
Gerhard
On Thu, 5 Apr 2007 02:03:20 -0400, Yosef Sugiharto Adikusumo
<YSAdikusumo@BANKBII.COM> wrote:
>Hi,I have a dataset with the following values.
>
>id date_1 date_2 XX lag_XX
>1AA 08aug06 23aug06 54 .
>1AA 08sep06 . . 54
>1AA 08oct06 . . .
>1AA 08nov06 . . .
>2BB 18aug06 3sep06 20 .
>2BB 18sep06 . . 20
>2BB 18oct06 . . .
>3CC 05aug06 18aug06 10 .
>3CC 05sep06 . . 10
>
>How can I change it to the following specification.
>such that the output looks like this
>
>id date_1 date_2 XX lag_XX
>1AA 08aug06 23aug06 54 .
>1AA 08sep06 . 84 54
>1AA 08oct06 . 124 84
>1AA 08nov06 . 154 124
>2BB 18aug06 3sep06 20 .
>2BB 18sep06 . 50 20
>2BB 18oct06 . 80 50
>3CC 05aug06 18aug06 10 .
>3CC 05sep06 . 40 10
>
>think I have to use a retain statement for lag_XX and update to XX
>variable??? but I dont know how to proceed.
>
>Thanks you all for your help as always
>YS
|