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
63
64
65
*(Q) I want to send a data variable as an argument to a macro. I want the
 macro to assign the valid values from the data variable to a macro
 variable.

*Let's say I send V1 to my macro. V1 can take on the values of 243, 78,
 432 or 8, so I want to assign those values to my macro variable and
 use it something like this:
 !DO !I !IN(!MACVAR) .
   iterate over the valid values from V1...
 !DOEND .

*Is this possible?


*(A) Posted to SPSS newsgroup on 2002/11/19 by Raynald Levesque.
* The following code does the job. 

SET MPRINT=no.
*////////////////////.
DEFINE !getval(fpath=!TOKENS(1) 
		/varn=!TOKENS(1))

GET FILE=!fpath.
COMPUTE nobreak=1.
AGGREGATE
  /OUTFILE=*
  /BREAK=!varn
  /nbval = N(nobreak).
COMPUTE nobreak=1.
MATCH FILES FILE=* /BY nobreak /LAST=last.

DO IF $CASENUM=1.
- WRITE OUTFILE='c:\\temp\\syntax.sps' /'DEFINE !macvar()'!varn.
ELSE IF NOT last.
- WRITE OUTFILE='c:\\temp\\syntax.sps' /' '!varn.
ELSE.
- WRITE OUTFILE='c:\\temp\\syntax.sps' /' '!varn'!ENDDEFINE.'.
END IF.
EXECUTE.


GET FILE=!fpath.
INCLUDE 'c:\\temp\\syntax.sps'.
!ENDDEFINE.
*////////////////////.


SET MPRINT=yes.

* Example 1.

!getval fpath ='c:\\program files\\spss\\employee data.sav'
	 varn  =educ.

* This is the content of the file syntax.sps.
DEFINE !macvar() 8
 12
 14
 15
 16
 17
 18
 19
 20
 21!ENDDEFINE.