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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
* This syntax illustrates a method to choose the INCLUDE file based on some tests done on the data.

* Type of approach is useful when you have 
1. a long syntax to run, 
2. the syntax is run on many different data files
3. depending on the presence of certain data, large section of the syntax become useless and should not be run.
* Raynald Levesque rlevesque@videotron.ca.

First, save the following 2 syntax files as 

*--------------Save as "c:\\temp\\syntax when NO 88.sps"-----------.
************.

* This is the syntax when there are NO values = to 88.
* Nothing to do.
*------------------------------------------------------------.

*--------------Save as "c:\\temp\\syntax when 88.sps"-----------.
************.

* This is the syntax when there are values = to 88.

FREQ VAR=M1R25REC.
*------------------------------------------------------------.


Then RUN the following syntax.

* Make 2 data files for illustration purposes.
DATA LIST FREE /M1R25REC.
BEGIN DATA
25 12 41 52 45 88 25 88 21 88 251 4 2 41 52
END DATA.
LIST.
SAVE OUTFILE='c:\\temp\\mydata1.sav'.

DATA LIST FREE /M1R25REC.
BEGIN DATA
25 12 41 52 45 44 25 45 21 46 251 4 2 41 52
END DATA.
LIST.
SAVE OUTFILE='c:\\temp\\mydata2.sav'.


* Get file with values equal to 88 to show that the correct syntax file is ran.
GET FILE='c:\\temp\\mydata1.sav'.
COMPUTE testvar=(M1R25REC EQ 88).
COMPUTE dummy=1.
AGGREGATE
  /OUTFILE='C:\\temp\\AGGR.SAV'
  /BREAK=dummy
  /nbcases = SUM(testvar).
MATCH FILES /FILE=*
 /TABLE='C:\\temp\\AGGR.SAV'
 /BY dummy.

DO IF $CASENUM=1 & nbcases=0.
WRITE OUTFILE='c:\\temp\\mysyntax.sps'
 /"INCLUDE FILE='c:\\temp\\syntax when NO 88.sps.'".
ELSE IF $CASENUM=1 & nbcases>0.
WRITE OUTFILE='c:\\temp\\mysyntax.sps'
 /"INCLUDE FILE='c:\\temp\\syntax when 88.sps.'".
END IF.
EXECUTE.

GET FILE='c:\\temp\\mydata1.sav'.
INCLUDE FILE='c:\\temp\\mysyntax.sps'.
* Continue with rest of syntax.


*######## Now illustrate when there are no values = 88.
GET FILE='c:\\temp\\mydata2.sav'.
COMPUTE testvar=(M1R25REC EQ 88).
COMPUTE dummy=1.
AGGREGATE
  /OUTFILE='C:\\temp\\AGGR.SAV'
  /BREAK=dummy
  /nbcases = SUM(testvar).
MATCH FILES /FILE=*
 /TABLE='C:\\temp\\AGGR.SAV'
 /BY dummy.

DO IF $CASENUM=1 & nbcases=0.
WRITE OUTFILE='c:\\temp\\mysyntax.sps'
 /"INCLUDE FILE='c:\\temp\\syntax when NO 88.sps.'".
ELSE IF $CASENUM=1 & nbcases>0.
WRITE OUTFILE='c:\\temp\\mysyntax.sps'
 /"INCLUDE FILE='c:\\temp\\syntax when 88.sps.'".
END IF.
EXECUTE.

GET FILE='c:\\temp\\mydata2.sav'.
INCLUDE FILE='c:\\temp\\mysyntax.sps'.
* Continue with rest of syntax.