1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
* (Q) How can I want to create a variable which is the cummulative sum of var1.

* (A) by Ray.

DATA LIST LIST /var1.
BEGIN DATA
1
4
.
6
.
10
END DATA.

* next line creates var2 which is the cumulative sum of var1 however
        cases with missing var1 values have missing var2 values
        (this behavior is as described in the documentation).

CREATE var2=CSUM(var1).

* Next line creates var3 which has a non missing value for cases (except for
        the first n cases when var1 has missing values for the first n vases).

DO IF $casenum=1.
COMPUTE var3=var1.
ELSE IF MISSING(var1).
COMPUTE var3=LAG(var3).
ELSE.
COMPUTE var3=var1 + LAG(var3).
END IF.
EXECUTE.

LIST.