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
* QUESTION: In a macro call there is an even number of variables given. How can I use those variables two by two?.

* ANSWER by rlevesque@videotron.ca.
* If question does not look clear, it will be clear after running the syntax and looking at output.
* This can be useful when the number of variables which will be input is unknown.

SET MPRINT=yes.

* Define dummy data file.
INPUT PROGRAM.
LOOP #cnt=1 TO 100.
DO REPEAT var=var001 var002 var002a var004 varc varz break1 ct.
COMPUTE var=RND(UNIFORM(5)).
END REPEAT.
END CASE.
END LOOP.
END FILE.
END INPUT PROGRAM.
SET MPRINT=yes.

*Define the macro.
DEFINE !macro (!POS=!CMDEND)
!LET !cnt=""
!DO !var !IN (!1)
!LET !cnt=!CONCAT(!cnt," ")

!IF (!LEN(!cnt)=1) !THEN !LET !arg1=!var
!ELSE
!LET !arg2=!var 
TABLES FORMAT=ZERO
 /PTOTAL=T1'YTD 2000' /TABLE CT + !arg1 + !arg2 BY break1 
 /STATISTICS=COUNT ('') CPCT (''(PCT4.0):break1 ). 
!IFEND

!IF (!LEN(!cnt)=2) !THEN !LET !cnt="" !IFEND

!DOEND
!ENDDEFINE.

* Call macro.
!macro var001 var002 var002a var004 varc varz.