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
*(Q) In the example below, everything works fine as long as
	values of 1, 2, and 3 exist (1=undergraduate students, 2=post-baccalaureate
	students, 3=masters students).  But, when the macro runs across an
	undergraduate program with no master's students, an SPSS warning is given
	and the macro is terminated. 

*(A) posted by Raynald Levesque to SPSS newsgroup on 2002/03/29.

**************.
* Illustration of the problem.
**************.

SET MPRINT=no.
DEFINE JMAC1 (V1=!TOKENS(1) / V2=!TOKENS(1))

/* Since jobcats is either 1,2 or 3, the following loop */
/* result in an error */
!DO !V3 = 1 !TO 4
get file = 'C:\Program Files\SPSS\employee data.sav'.
select if (gender = !V1 and jobcat = !V3).
FREQ VAR=jobcat.
LIST.
!DOEND.

!ENDDEFINE.


SET MPRINT=yes.
INCLUDE 'c:\temp\CB1_DEPT.MAC'.
EXECUTE.


**************.
*One possible solution.
**************.
SET MPRINT=no.

*///////////////.
DEFINE JMAC1 (V1=!TOKENS(1) / V2=!TOKENS(1))

* Since jobcats is either 1,2 or 3, the following loop would.
* normally result in an error.
!DO !V3 = 1 !TO 4
get file = 'C:\Program Files\SPSS\employee data.sav'.

* add the case with all empty values.
ADD FILES FILE=* /FILE='c:\temp\empty.sav'.

* Note that 'or MISSING(id)' has been added in next line.
SELECT IF (gender = !V1 and jobcat = !V3) OR MISSING(id).
FREQ VAR=id.
LIST.
!DOEND.

!ENDDEFINE.
*///////////////.


* Do some preparatory work then call macro.
* Create a one case data file where all cases are missing.

get file = 'C:\Program Files\SPSS\employee data.sav'.
N OF CASES 1.
SET ERRORS=none.
DO REPEAT var=ALL.
COMPUTE var=$SYSMIS.
COMPUTE var="".
END REPEAT.

SET ERRORS=listing.
SAVE OUTFILE='c:\temp\empty.sav'.

SET MPRINT=yes.
INCLUDE 'c:\temp\CB1_DEPT.MAC'.