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
* Some commands do not accept references such as var1 TO xyz5.
* This macro produces a list of all variables between 2 given variables.
* The macro is useful when there are hundreds of variables.
* Because of a 'feature' of the macro parser, it is sometimes necessary to enclose 
the variable names in quotes. This is done in the macro qlist1 (see below).
* Raynald Levesque rlevesque@videotron.ca 2001/03/24.


*///////////////////////////////////////.
DEFINE !DefList (var1=!TOKENS(1) 
		/var2=!TOKENS(1) 
		/fname=!CMDEND)

GET FILE=!fname.
COMPUTE dummy=1.
N OF CASES 1.
MATCH FILES FILE=* /BY dummy /KEEP=!var1 TO !var2.
FLIP.
COMPUTE dummy=1.

MATCH FILES FILE=* /BY dummy /FIRST=first /LAST=last.
DO IF first.
WRITE OUTFILE='c:\\temp\\list1.sps' / 'DEFINE !list1()' case_lbl.
WRITE OUTFILE='c:\\temp\\qlist1.sps' / 'DEFINE !qlist1()"' case_lbl'"'.
ELSE if not last.
WRITE OUTFILE='c:\\temp\\list1.sps' / " "case_lbl.
WRITE OUTFILE='c:\\temp\\qlist1.sps' / " '"case_lbl"'".
ELSE.
WRITE OUTFILE='c:\\temp\\list1.sps' /" "case_lbl ' !ENDDEFINE'.
WRITE OUTFILE='c:\\temp\\qlist1.sps' /" '"case_lbl"'" ' !ENDDEFINE'.
END IF.
EXECUTE.

GET FILE=!fname.
INCLUDE FILE='c:\\temp\\list1.sps'.
* qlist1 = list1 with quoted variable names.
INCLUDE FILE='c:\\temp\\qlist1.sps'.
!ENDDEFINE.
*///////////////////////////////////////.

* I assume the 600 variables are consecutives, that is, there are no string variables between the first and 600th numeric variables.
* Here I use only 5 variables to illustrate the procedure.
* Assume we want to round the values to the nearest integer and change the format to F8.0.

DATA LIST LIST /g x345 v3 b k.
BEGIN DATA.
1.21 2.49 3.01 5.51 41.98 
2.33 5.67 1.75 4.22 6.02 
END DATA.

SAVE OUTFILE='c:\\temp\\mydata.sav'.
EXECUTE.
SET MPRINT=yes.

* The following code does the job. 
!DEfList var1=g var2=k fname="c:\\temp\\mydata.sav".

DO REPEAT v=!list1.
	COMPUTE v=RND(v).
	FORMATS v(F8.0).
END REPEAT PRINT.
EXECUTE.