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
*(Q) How can I get automatically compute the variable "newvar" in the table below?

*(A) Posted to SPSSX-L list by rlevesque@videotron.ca on 2002/11/04.


DATA LIST LIST /v1  v2  v3  v4  newvar.
BEGIN DATA.
1   2   .    4   124
1   .    3   .    13
.    2   .    .    2
1   2   3     .  123
.  .      3   .    3
1   2    .   4   124
END DATA.
LIST.

* first method (LOOP).
VECTOR v=v1 TO v4.
COMPUTE newvar2=0.
LOOP #cnt=1 TO 4.
IF ~MISSING(v(#cnt)) newvar2=newvar2*10 + v(#cnt).
END LOOP.

* second method (DO REPEAT).
COMPUTE newvar3=0.
DO REPEAT v=v1 TO v4.
IF ~MISSING(v) newvar3=newvar3*10 + v.
END REPEAT.
EXECUTE.