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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
*(Q)I have an SPSS syntax question, given the following variable

VAR1
.
.
.
10/5/2001
.
10/3/2001
.
.

I would like to compute (in this case) 2 new constant variables
containing the 'non-zero' dates 10/5/2001 and 10/3/2001. In a more
general case how would one go about setting up constant date variables
from VAR1 when the number of 'non-zero' dates in VAR1 is unknown?

*(A) Posted to SPSSX-L on 2001/10/05 by rlevesque@videotron.ca.


DATA LIST LIST /VAR1(ADATE).
BEGIN DATA
.
.
.
10/5/2001
.
10/3/2001
.
.
END DATA.
LIST.
SAVE OUTFILE='c:\\temp\\mydata.sav'.

FORMATS var1(F14.2).
STRING cst(A8) .

DO IF $CASENUM=1.
+	COMPUTE idx=~MISSING(var1).
+	DO IF ~MISSING(var1).
+		COMPUTE cst=CONCAT('c',LTRIM(STRING(idx,F7.0))).
+		WRITE OUTFILE 'c:\\temp\\syntax.sps' 
			/"COMPUTE ",cst,"=",var1,"."
			/"FORMATS ",cst,"(ADATE11).".
+	END IF.
ELSE IF ~MISSING(var1).
+	COMPUTE idx=LAG(idx)+1.
+	COMPUTE cst=CONCAT('c',LTRIM(STRING(idx,F7.0))).
+	WRITE OUTFILE 'c:\\temp\\syntax.sps' 
		/"COMPUTE ",cst,"=",var1,"."
		/"FORMATS ",cst,"(ADATE11).".
ELSE.
+	COMPUTE idx=LAG(idx).
END IF.
EXECUTE.

GET FILE='c:\\temp\\mydata.sav'.
INCLUDE FILE='c:\\temp\\syntax.sps'.
VARIABLE WIDTH ALL(10).
EXECUTE.