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
* (Q) How can I automatically delete all variables where all values are 0?
* (A) Posted to SPSSX-L list by Raynald Levesque on 2004/01/09.

* paste the list of variables in the next macro definition then run the syntax.

define !varlist()v1 v2 v3!enddefine.

data list list / v1   v2   v3.
begin data
0     0      1
1     0      1
0     0      0
0     0      0
end data.
save outfile='c:\\temp\\data.sav'.

compute nobreak=1.
aggregate outfile='c:\\temp\\file1.sav'
	/pre
	/break=nobreak
	/!varlist=MAX(!varlist).
aggregate outfile=*
	/pre
	/break=nobreak
	/!varlist=MIN(!varlist).
add files file=*
	/file='c:\\temp\\file1.sav'.
execute.
aggregate outfile=*
	/pre
	/break=nobreak
	/!varlist=SUM(!varlist).
flip.
select if var001=0.
do if $casenum=1.
- write outfile='c:\\temp\\delete var.sps' /'add files file=* /drop='case_lbl.
else. 
- write outfile='c:\\temp\\delete var.sps' /' 'case_lbl.
end if.
execute.

get file='c:\\temp\\data.sav'.
include 'c:\\temp\\delete var.sps' .
execute.