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
*QUESTION: How can I have a syntax which will vary depending on the name of the datafile?

*ANSWER by rlevesque@videotron.ca. 

*Try the following approach.
set mprint=on.

* Create 3 sample data files for demonstration purposes.
DATA LIST LIST /x1(F8) x2(F8).
BEGIN DATA.
2 1 
1 2 
5 3 
END DATA.
SAVE OUTFILE='C:\\temp\\std_data.sav'.

DATA LIST LIST /y1(F8) y2(F8).
BEGIN DATA.
5 2 
4 3 
4 3 
END DATA.
SAVE OUTFILE='C:\\temp\\XXdata.sav'.

DATA LIST LIST /z1(F8) z2(F8).
BEGIN DATA.
8 3 
8 1 
5 2
5 6
END DATA.
SAVE OUTFILE='C:\\temp\\XYdata.sav'.

****** Define a macro.
DEFINE !doit (filenam=!TOKENS(1))
get file=!QUOTE(!CONCAT('C:\\temp\\',!filenam,'.sav')).

!IF ((!filenam !NE 'XXdata') !AND (!filenam !NE 'XYdata')) !THEN
/*do your standard analyses (standard vars: X1,X2).
FREQ VAR=x1 x2.
!IFEND 

!IF (!filenam !EQ 'XXdata') !THEN
/*do your nonstandard analyses (non-standard vars: Y1,Y2).
FREQ VAR=y1 y2.
!IFEND 

!IF (!filenam !EQ 'XYdata') !THEN
*do your nonstandard analyses (non-standard vars: Z1,Z2).
FREQ VAR=z1 z2.
!IFEND

!ENDDEFINE.

* Call the macro.
!doit filenam=std_data.
!doit filenam=XXdata.
!doit filenam=XYdata.