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
* Many macros use procedures that require an 'open' data set in the editor, even if
* the macro procedure doesn't use the data. The data list command doesn't work inside
* a macro, but matrix code can be incorporated as a first line for a macro that uses
* commands requiring open data. The following is a macro that uses this technique to
* generate normally distributed random data. 
* Author: Fernando Cartwright, Ottawa, Canada
* 2004/11/15.

NEW FILE.

DEFINE mymacro (!POS !TOKENS(1))

/*opens matrix language*/
MATRIX.
COMPUTE temp=1.
COMPUTE mylength=(!1-1).

/*loop across the number of records specified in the macro call*/
LOOP i=1 to mylength.
COMPUTE temp={temp;1}.
END LOOP.

/*place the records in the open data editor*/
SAVE temp
 /outfile=*
 /variables=temp.
END MATRIX.

COMPUTE random=RV.NORMAL(0,1).
EXECUTE.

!END DEFINE.

/*run by specifying the number of records in the new file*/

mymacro 15.