1
votes

The data set is like this:

V1 V2 V3 V4 V5 
x  1  2  n  .
x  3  4  .  .
x  5  6          

If I want to calculate

V5 = V4 - V3
V4 = V5(previous line) + V2

How can I do it using syntax?

1

1 Answers

2
votes

Use the LAG operator to access elements in the previous row.

DATA LIST FREE / V1 to V5.
BEGIN DATA
1 2 3 4 5
4 5 6 7 8
7 8 9 0 1
END DATA.

COMPUTE V5_2 = V4 - V3.
COMPUTE V4_2 = LAG(V5) + V2.