Examples (DEFINE-!ENDDEFINE command)
Example
* Macro without arguments: Specify a group of variables.
DEFINE sesvars ()
age sex educ religion
!ENDDEFINE.
FREQUENCIES VARIABLES=sesvars.
- The macro name is
sesvars. Because the parentheses are empty,sesvarshas no arguments. The macro body defines four variables: age, sex, educ, and religion. - The macro call is specified on
FREQUENCIES. When the call is executed,sesvarsis expanded into the variables age, sex, educ, and religion. - After the macro expansion,
FREQUENCIESis executed.
Example
* Macro without arguments: Repeat a sequence of commands.
DATA LIST FILE = MAC4D /GROUP 1 REACTIME 3-5 ACCURACY 7-9.
VALUE LABELS GROUP 1'normal'
2'learning disabled'.
* Macro definition.
DEFINE check ()
split file by group.
frequencies variables = reactime accuracy
/histogram.
descriptives reactime accuracy.
list.
split file off.
regression variables = group reactime accuracy
/dependent = accuracy
/enter
/scatterplot (reactime, accuracy).
!ENDDEFINE.
check. /* First call of defined macro check
COMPUTE REACTIME = SQRT (REACTIME).
COMPUTE ACCURACY = SQRT (ACCURACY).
check. /* Second call of defined macro check
COMPUTE REACTIME = lg10 (REACTIME * REACTIME).
COMPUTE ACCURACY = lg10 (ACCURACY * ACCURACY).
check. /* Third call of defined macro check
- The name of the macro is
check. The empty parentheses indicate that there are no arguments to the macro. - The macro definition (between
DEFINEand!ENDDEFINE) contains the command sequence to be repeated:SPLIT FILE,FREQUENCIES,DESCRIPTIVES,LIST,SPLIT FILE, andREGRESSION. - The macro is called three times. Every time
checkis encountered, it is replaced with the command sequenceSPLIT FILE,FREQUENCIES,DESCRIPTIVES,LIST,SPLIT FILE OFF, andREGRESSION. The command sequence using the macro facility is identical to the command sequence in which the specified commands are explicitly stated three separate times.
Example
* Macro with an argument.
DEFINE myfreq (vars = !CHAREND('/'))
frequencies variables = !vars
/format = notable
/statistics = default skewness kurtosis.
!ENDDEFINE.
myfreq vars = age sex educ religion /.
- The macro definition defines
varsas the macro argument. In the macro call, four variables are specified as the argument to the macromyfreq. When the program expands themyfreqmacro, it substitutes the argument,age,sex,educ, andreligion, for!varsand executes the resulting commands.