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, sesvars has 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, sesvars is expanded into the variables age, sex, educ, and religion.
- After the macro expansion, FREQUENCIES is 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 DEFINE and !ENDDEFINE) contains the command sequence to be repeated: SPLIT FILE, FREQUENCIES, DESCRIPTIVES, LIST, SPLIT FILE, and REGRESSION.
- The macro is called three times. Every time check is encountered, it is replaced with the command sequence SPLIT FILE, FREQUENCIES, DESCRIPTIVES, LIST, SPLIT FILE OFF, and REGRESSION. 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 vars as the macro argument. In the macro call, four variables are specified as the argument to the macro myfreq. When the program expands the myfreq macro, it substitutes the argument, age, sex, educ, and religion, for !vars and executes the resulting commands.