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
*(Q)  I am creating a large number of bar charts. For each chart I must exclude any 
	categories that have fewer than 10 students. I have been running frequencies and
	 then manually clicking on each category that was to be omitted, but I know there 
	must be a better way. Any ideas would be greatly appreciated. 

*(A) Posted to SPSSX-L list by rlevesque@videotron.ca on 2001/09/21
	Two different macros are included. Select the one which best
	meet your requirements.


DATA LIST LIST /age prog year.
BEGIN DATA 
25 1 2
25 1 2 
25 1 2 
25 1 2 
25 1 4
25 1 4
25 1 4
25 1 4
25 1 4
25 1 4
25 1 7
25 1 7
25 1 7
25 1 7
25 1 2
26 1 2
27 2 1
27 2 1
27 2 1
27 2 1
27 2 1
27 2 1
END DATA.

COMPUTE dummy=1.
SET MPRINT=no.

*////////////////////.
DEFINE !chart (minnb=!TOKENS(1) /cat=!TOKENS(1))

FILTER OFF.
* Sorting is necessary for the MATCH FILES command.
SORT CASES BY !cat.
!LET !fname=!QUOTE(!CONCAT('C:\\temp\\',!cat,'.SAV'))
AGGREGATE
  /OUTFILE=!fname
  /PRESORTED
  /BREAK=!cat
  /nb = N(dummy).

MATCH FILES /FILE=*
 /TABLE=!fname
 /BY !cat.
FREQUENCY VARIABLES=!cat.

COMPUTE flag=(nb>=!minnb).
FILTER BY flag.
GRAPH
  /BAR(SIMPLE)=COUNT BY !cat
  /MISSING=REPORT.
* Delete the variable nb.
MATCH FILES FILE=* /DROP=nb.
!ENDDEFINE.
*////////////////////.

SET MPRINT=yes.
!chart minnb=5 cat=age.
!chart minnb=6 cat=prog.
!chart minnb=5 cat=year.

* The above method is ok if you need to do other things between 
	the printing of the charts.

* The following macro is ok if all you need is to print the bar charts
	and the same min number of cases is required..

SET MPRINT=no.
*////////////////////.
DEFINE !chart2 (minnb=!TOKENS(1) /cats=!CMDEND)
/* minnb = minimum number of cases required in order to chart category value*/.
/* cats    = names of the categorical variables to be charted*/.

COMPUTE dummy=1.
!DO !cat !IN (!cats)
FILTER OFF.
* Sorting is necessary for the MATCH FILES command.
SORT CASES BY !cat.
!LET !fname=!QUOTE(!CONCAT('C:\\temp\\',!cat,'.SAV'))
AGGREGATE
  /OUTFILE=!fname
  /PRESORTED
  /BREAK=!cat
  /nb = N(dummy).

MATCH FILES /FILE=*
 /TABLE=!fname
 /BY !cat.
FREQUENCY VARIABLES=!cat.
LIST.
COMPUTE flag=(nb>=!minnb).
FILTER BY flag.
GRAPH
  /BAR(SIMPLE)=COUNT BY !cat
  /MISSING=REPORT.
* Delete the variable nb.
MATCH FILES FILE=* /DROP=nb.
!DOEND
* Delete the variable nb.
MATCH FILES FILE=* /DROP=dummy.
!ENDDEFINE.
*///////////////////

SET MPRINT=yes.
!chart2 minnb=5 cats= age prog year.
EXECUTE.