I have the following column:
0.1 0.5 0.23 . 0.5 0.67 0.23 0.42 . . . 0.12 0.20
Where dots indicate that there was no data available at that time.
Now I want to compute the difference in growth between the current case and the last available case. Thus, in the second last case this should become:
0.12 - 0.42 = -0.30.
Lag(growth) takes the last case, and returns nothing if it is not defined. So how do I get the last available case?
This seems to work:
define !lastAvailable(target !Tokens(1) /level !Tokens(1) /Varys !CMDEND) compute id= $casenum. dataset copy tmpset2. select if not miss(!target). compute diff= !target - lag(!target, !level). match files /file= * /file= tmpset2 /by id. exec. dataset close tmpset2. !enddefine. !lastAvailable target=growth level=3