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
* XpandVectorNames.SPS.

* Macro posted to SPSSX-L on 2001/03/15 by Hauke Petersen hauke.petersen@INTERACTIVEMEDIA.DE.

* This macro allows to easily reference a vector (all variables whose names fall between, say,
* a1 and a40) even when these variables are NOT in consecutive order in the data editor. See notes at the end.

DATA LIST LIST /a.
BEGIN DATA
1
END DATA.
LIST.

* Following variables are not in consecutive order.
NUMERIC a1 b02 a4 b01 a3 b03 a2.

SET MPRINT=yes.
define !xpand(!pos !tokens(1) / !pos !tokens(1) / !pos !tokens(1))
!do !i=!2 !to !3 !concat(!1,!i," ") !doend
!enddefine.

* Example of use of the macro.
* List variables in consecutive order.
LIST !xpand a 1 4 !xpand b0 1 3.

* File may also be sorted in the right order for the variables a1 TO a4 for instance.
COMPUTE dummy=1.
MATCH FILES FILE=* /BY=dummy /KEEP=!xpand a 1 4 ALL.

********************.
* Raynald's notes: 
********************.

* 1. the macro !xpand should be placed on an existing line (not on a new line). For instance, the following command
* does not work because the second macro calls starts on a new line.
LIST !xpand a 1 4 
	!xpand b0 1 3.

* 2. The macro is also useful when the "var1 TO var10" form does not work, an example is when we
* need a loop of the type 
!DO !var !IN (!list)
where !list is one of the macro parameter. Such a macro may be call using something such as 
list=!xpand var 1 10.