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
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
* (Q) How can I add a footnote at the bottom of each table showing the number of valid cases used?

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

******************************.
* First a "simple" solution.
******************************.

SET MPRINT=ON.

DATA LIST LIST /id(F8) var1(F8).
BEGIN DATA.
1 10
2 15 
3 10 
4 20
5 25
6 15
7 25
8  
9  
END DATA.
LIST.

SAVE OUTFILE='c:\\temp\\data.sav'.

COMPUTE nvalid=(NMISS(var1)=0).
COMPUTE aggrv = 1 .
AGGREGATE
  /OUTFILE*
  /BREAK=nvalid
  /aggrv_1 = SUM(aggrv).

DO IF nvalid=1.
WRITE OUTFILE 'c:\\temp\\data.sps'
  /"DEFINE !sum_1()'Number of valid cases ="aggrv_1"'!ENDDEFINE.".
END IF.
EXE.

GET FILE='c:\\temp\\data.sav'.
INCLUDE 'c:\\temp\\data.sps'.

 *General Tables.
  TABLES
  /FORMAT BLANK MISSING('.')
  /GBASE=CASES
  /FTOTAL= $t000001 "Total"
  /TABLE=var1 + $t000001  BY (STATISTICS)
  /STATISTICS
  count( var1( F5.0 ))
  cpct( var1( PCT5.1 ) 'Col %')
  /SORT=D var1
  /caption=!sum_1 .

***END OF JOB.

**################.
Next section is to generalize the process.
**################.

DATA LIST LIST /id(F8) var1(F8) var22(F8).
BEGIN DATA.
1 10 1
2 15 2 
3 10 4 
4 20 .
5 25 5
6 15 4
7 25 .
8 .  5
9 . . 
END DATA.
LIST.

SAVE OUTFILE='c:\\temp\\data.sav'.

*/////////////////.
DEFINE !getval(namemac=!TOKENS(1)
	/vars=!CMDEND)
COMPUTE nvalid=(NMISS(!vars)=0).
COMPUTE aggrv = 1 .
AGGREGATE
  /OUTFILE*
  /BREAK=nvalid
  /aggrv_1 = SUM(aggrv).

DO IF nvalid=1.
!LET !tmp=!QUOTE(!CONCAT('DEFINE !',!namemac,'()'))
WRITE OUTFILE 'c:\\temp\\data.sps'
  /!tmp "'Number of valid cases ="aggrv_1"'!ENDDEFINE.".
END IF.
EXE.

GET FILE='c:\\temp\\data.sav'.
INCLUDE FILE='c:\\temp\\data.sps'.
!ENDDEFINE.
*/////////////////.


*******************.
*** Example 1 *****.
*******************.

GET FILE='c:\\temp\\data.sav'.
* Call macro to define the macro containing the number of cases.
!getval namemac=nb1 vars=var1.
* Reload the data file.
GET FILE='c:\\temp\\data.sav'.
 *General Tables.
  TABLES
  /FORMAT BLANK MISSING('.')
  /GBASE=CASES
  /FTOTAL= $t000001 "Total"
  /TABLE=var1 + $t000001  BY (STATISTICS)
  /STATISTICS
  count( var1( F5.0 ))
  cpct( var1( PCT5.1 ) 'Col %')
  /SORT=D var1
  /caption=!nb1.


*******************.
*** Example 2 *****.
*******************.


GET FILE='c:\\temp\\data.sav'.
* Call macro to define the macro containing the number of cases
	where both var1 and var22 exist.
!getval namemac=nb2 vars=var1,var22.
* Reload the data file.
GET FILE='c:\\temp\\data.sav'.
 *General Tables.
  TABLES
  /FORMAT BLANK MISSING('.')
  /GBASE=CASES
  /FTOTAL= $t000001 "Total"
  /TABLE=var1 + $t000001  BY (STATISTICS)
  /STATISTICS
  count( var1( F5.0 ))
  cpct( var1( PCT5.1 ) 'Col %')
  /SORT=D var1
  /caption=!nb2.

* Of course the above TABLES command would be changed to show whatever is 
	required.