Using Subcommands
    

Local macros can also have subcommands that can modify the behavior of the macro-just as subcommands in interactive Minitab can change the behavior of a command. Subcommands can have their own arguments. You can also choose to include or not include the subcommand when invoking the local macro.

For example, the scatter plot macro described above could be made more flexible by including a subcommand that lets you decide at what level the confidence bands should be drawn.

To add subcommands to a macro

·    Write a template that includes a subcommand.

·    If any of your subcommands include arguments, you must declare the variable data type for those arguments in the declaration statements

·    If any of your subcommands include arguments that are constants, you can assign default statements to those arguments in the body of the macro.

Invoking macros that use subcommands

·    When invoking a macro, if you type a subcommand more than once, Minitab uses the first occurrence of the subcommand.

·    Individual arguments on subcommands cannot be optional. For example, suppose a subcommand has two arguments. When you invoke the macro, you can either omit the subcommand entirely, thereby accepting the default, or use it with two arguments. You cannot use the subcommand with the data value for one argument and take a default for the other argument.

Example of creating and invoking a macro with a subcommand

Suppose we improve TRIM by adding an optional subcommand, PERCENT, that allows the user to specify the trimming percent. If the user does not specify PERCENT, we use the default value of 5%. We give this default value using the macro statement DEFAULT.

Here what you would type for the macro:

MACRO
TRIM2 X XBAR;
      PERCENT PCT.
    #
    # TRIM2 takes one column, X, as input. It orders the data, trims
    # the percent specified by PCT from each end, calculates the
    # mean of the remaining data and stores it in XBAR.
    # If PCT is not given, 5% is used.
    #
    MCONSTANT N T1 T2 XBAR PCT
    MCOLUMN    X XSORT XTRIM
    DEFAULT     PCT = 5
    #You can find the complete version of this macro in the file TRIM2.MAC.

Then suppose, in your global worksheet, you have data in a column named Score and you want to calculate the 4% trimmed mean and store it in a constant named Sbar. When you invoke a macro, you must use single-quotes around variable names, as with most other Minitab commands. It is only in the macro text that quotes are not used.

Here is what you would type for invoking the macro:

%TRIM2 'Score' 'Sbar';
  PERCENT 4.

Determining whether or not the subcommand invokes

Assigning default values to subcommand arguments