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
* Reorder vector names in data files.

* This is useful when you have vectors say a1 TO a50, b1 TO b50, c1 TO c50.
* and you want to reorder them as a1 b1 c1 a2 b2 c2 ... a50 b50 c50.
* Raynald Levesque 2001/04/28.

DATA LIST LIST /dummy.
BEGIN DATA
1
END DATA.
LIST.

* Following vectors are "consecutive" (all a's, all b's then all c's).
NUMERIC id x y a1 TO a50 z1 b1 TO b50  z2 c1 TO c50 k.
* Say we want to Reorder vectors a b c "side by side" that is a1 b1 c1 a2 b2 c2 ... a50 b50 c50.
SET MPRINT=yes.

*//////////////////////.
DEFINE !reorder (id=!TOKENS(1) /beg !TOKENS(1) / end !TOKENS(1) /vnames !CMDEND)
MATCH FILES FILE=* /KEEP=!id !DO !i=!beg !TO !end !DO !var !IN (!vnames) !CONCAT(!var,!i," ") !DOEND !DOEND ALL.
!ENDDEFINE.
*//////////////////////.

* Example of use of the macro.

!reorder id=id beg=1 end=50 vnames=a b c.

**********************.
*** Explanations***.
**********************.

* The following format helps to understand the !DO - !END loops in the above match command, 
*!DO !i=!beg !TO !end 
*	!DO !var !IN (!vnames) 
*		!CONCAT(!var,!i," ") 
*	!DOEND 
*!DOEND
*ALL.

* NOTES:
* ALL means keep all other variables not previously named.
* The macro loop is written in one line to reduce the number of lines in the syntax file being created.
* Note that macro commands do NOT need a command terminator (a decimal point) at the
    end. In fact if periods had been inserted after 
    !DO !i=!beg !TO !end 
    for instance, the macro would no longer work! because this period would
    effectively "end" the MATCH FILES command.