You may have two or more macros in one file. Each macro in the file follows the usual structure (beginning with GMACRO or MACRO, ending with ENDMACRO, etc.), and each must have a unique template name. When you invoke a macro, Minitab executes the first macro in the file. Subsequent macros in the file are subroutines that you can invoke using a CALL statement. There are some restrictions on which type of macro another macro can call:
From within this type of macro |
You can invoke... |
Global |
Global |
|
Exec |
Local |
|
Local |
|
Exec |
Global |
Local |
Exec |
You invoke a macro from within a macro in the same way you invoke a macro from the Minitab prompt. On a line, put the symbol % followed by the name of the macro file, as in %TRIM. You can also include a path statement, as in %C:\MYWORK\TRIM. If it is a local macro, include all appropriate arguments and subcommands.
Because the macros you execute are stored in your worksheet area, the only limitation to the number of macros you can nest is the amount of space available in your worksheet.
The following example improves the global macro ANALYZE to handle the case when a data set is too small to analyze. The main file, stored as ANALYZE2.MAC, determines how many observations are in the data set. If there are fewer than 5, it invokes the macro file TOOSMALL.MAC. TOOSMALL prints out a message then prints the data set. If the data set has at least 5 observations, ANALYZE2 invokes the macro file OK.MAC. OK is the same as the original version, ANALYZE.
GMACRO
ANALYZE2
#
LET K90 = COUNT(C1)
IF K90 < 5
%TOOSMALL
ELSE
%OK
ENDIF
ENDMACRO
GMACRO
TOOSMALL
#
NOTE Data set has fewer than 5 observations.
NOTE No analysis will be done. Here are the data.
PRINT C1 - C3
ENDMACRO
GMACRO
OK
#
NAME C1 = 'Yield' C2 = 'Chem1' C3 = 'Chem2' C5 = 'Ln.Yield'
PRINT C1-C3
DESCRIBE C1-C3
LET C5 = LOGE('Yield')
REGRESS C5 2 C2 C3
ENDMACRO