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
* (Q) Does anyone know if there is a way to run a frequency for a variable and
only display the top 10 (either descending or ascending) in the output?

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

SET MPRINT=no.
*////////////////////.
DEFINE !freq (keep=!TOKENS(1) 
	/order=!TOKENS(1)
	/cat=!TOKENS(1) 
	/fname=!TOKENS(1))
GET FILE=!fname.
COMPUTE dummy=1.

!LET !fname2=!QUOTE(!CONCAT('C:\\temp\\',!cat,'.SAV'))
AGGREGATE
  /OUTFILE=*
  /BREAK=!cat
  /nb = N(dummy).
SORT CASES BY nb !CONCAT('(',!order,')').
EXECUTE.

N OF CASES !keep.
* Sorting is necessary for the MATCH FILES command.
SORT CASES BY !cat.
SAVE OUTFILE=!fname2.
GET FILE=!fname.
SORT CASES BY !cat.
MATCH FILES /FILE=*
 /TABLE=!fname2
 /BY !cat.

COMPUTE flag=~MISSING(nb).
FILTER BY flag.
FREQUENCIES
  VARIABLES=!cat
  /ORDER=  ANALYSIS .
* Delete the variable nb.
MATCH FILES FILE=* /DROP=nb.
!ENDDEFINE.
*////////////////////.

SET MPRINT=yes.


* Print only educ having LOWEST 3 frequency.
!freq keep=3
	order=A
	cat=educ 
	fname='c:\\program files\\spss\\employee data.sav'.
EXECUTE.

* Print only educ having HIGHEST 5 frequency.
!freq keep=5
	order=D
	cat=educ 
	fname='c:\\program files\\spss\\employee data.sav'.
EXECUTE.

* Print all for checking purposes*.
GET FILE='c:\\program files\\spss\\employee data.sav'.
FREQ VAR=educ.