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
*(Q) My macro has two parameters: yfirst and ylast
	The macro creates variables of the format sXXXX where
	XXXX goes from yfirst to ylast. How can I have a loop in the 
	/KEEP subcommand of SAVE OUTFILE in order to list the sXXXX variables?.

*(A) By posted to spss newsgroup by Raynald Levesque on 2002/05/15.


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

DEFINE !test(yfirst=!TOKENS(1) /ylast=!TOKENS(1))
!LET !list=!NULL
/*calculate some values for sXXXX. */
!DO !cnt=!yfirst !TO !ylast
COMPUTE !CONCAT('s',!cnt)=!cnt.
!LET !list=!CONCAT(!list,' ',!CONCAT('s',!cnt))
!DOEND

/*Save the sXXXX variables */
SAVE OUTFILE='c:\\temp\\test.sav' /KEEP=!list.
!ENDDEFINE.

SET MPRINT=yes.
!test yfirst=1990 ylast=2002.
SET MPRINT=no.

* Note that the above method works even if the sXXXX variables are not 
	consecutive in the data file.