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
66
67
68
69
70
71
72
73
74
75
76
77
78
*(Q) I have several raw ASCII data files defined by a file handle
statement.  I need to apply the same data list to each of them as an include
statement.  In logical order it would look like:

file handle show1 /name='c:\\temp\\file1.txt'.
include file='c:\\temp\\data_list.sps'.
*some procedures.
file handle show2 /name='c:\\temp\\file2.txt'.
include file='c:\\temp\\data_list.sps'.

*This, of course doesn't work because the first line of the data list has to
define which file it applies to, in this case a file called "show," e.g.,
DATA LIST FILE = SHOW (without the numbers and applying to only one file it
works just fine).  The data list file is a standard file at my new job so I
don't really have the option of changing it.

* (A) rlevesque@videotron.ca 2001/12/22 (not previously posted).

* Write first data file.
DATA LIST /str 1-4(A).
BEGIN DATA
1 1
1 2
1 3
END DATA.
WRITE OUTFILE='c:\\temp\\file1.txt' /str.
EXECUTE.

* Write second data file.
DATA LIST /str 1-4(A).
BEGIN DATA
2 1
2 2
2 3
END DATA.
WRITE OUTFILE='c:\\temp\\file2.txt' /str.
EXECUTE.

* Write the standard DATA LIST.
DATA LIST /str 1-80(A).
BEGIN DATA
* This is a comment.
DATA LIST LIST /filenb casenb.
* This also a comment line.
COMPUTE casenb=casenb*2.
END DATA.
WRITE OUTFILE='c:\\temp\\data_list.sps' /str.
EXECUTE.

SET MPRINT=no.
*/////////////////////.
DEFINE !doit (fname=!TOKENS(1) /fpath=!TOKENS(1))
/* Read the data list file*/
DATA LIST FIXED FILE='c:\\temp\\data_list.sps' /line 1-80(A).
LIST.

* Re-write the 'data list.sps' inserting the file name in the data list.
DO IF $CASENUM=1.
WRITE OUTFILE='c:\\temp\\syntax.sps' /'FILE HANDLE ' !QUOTE(!fname) ' /NAME=' !QUOTE(!fpath) '.'.
END IF.

DO IF UPCASE(SUBSTR(line,1,9))='DATA LIST'.
STRING newline(A80).
COMPUTE newline=CONCAT('DATA LIST FILE=',!QUOTE(!fname),SUBSTR(line,10)).
WRITE OUTFILE='c:\\temp\\syntax.sps' /newline.
ELSE.
WRITE OUTFILE='c:\\temp\\syntax.sps' /line.
END IF.
EXECUTE.
INCLUDE FILE='c:\\temp\\syntax.sps'.
/* some procedures here */.
EXECUTE.
!ENDDEFINE.
*//////////////////.

SET MPRINT=yes.
!doit fname=show fpath='c:\\temp\\file1.txt'.
!doit fname=show2 fpath='c:\\temp\\file2.txt'.