Declaration Statements
    

All variables used in a local macro must be declared. Declaring a variable tells the local macro what type of variable to expect from the user, or the macro, while invoking.

Declaration Requirements

·    Declare variables that are constants with MCONSTANT, variables that are columns with MCOLUMN, and variables that are matrices with MMATRIX. (You may also use the plural synonyms MCONSTANTS, MCOLUMNS, and MMATRICES.) After the M- command, list all the variables that are of that type, separated by a space.

·    An argument, which is a variable in the template, may be given the declaration MFREE. The variable data type-column, constant, or matrix-is determined by the type of the variable that is given when the macro is invoked. The macro statement MTYPE allows you to determine whether a variable declared with MFREE is a column, constant, or matrix.

·    You may use a declaration statement several times, but only for different variables and only between the template and the body of the macro. Once a variable is declared, it cannot be redeclared. Variable declarations can only be made between the template and the body of the macro.

·    The declaration commands (MCOLUMN, MCONSTANT, etc.) cannot be abbreviated.

·    The declared variable must have a legal name.

Example of declaring variables

For example, suppose the template is

TRIM X Xbar

TRIM is the name of the macro and X and Xbar are variables that will be passed into the macro. The macro would need declaration statements that define whether X and Xbar are constants, columns, matrices, or "free" variables (defined below). Let's say X is a column in the global worksheet and Xbar is a constant in the global worksheet. The user would invoke the macro by typing, say, %TRIM C5 K1. The first few lines of the local macro file would then be

MACRO

TRIM X Xbar

MCOLUMN X

MCONSTANT Xbar

Note    If you see the error "Missing END for READ, SET, or INSERT," it may be because you have named a local variable with the same name as a Minitab command, and entered it after READ, SET, or INSERT. For example:

    SET col1
min:max/1
END

    where min and max are local variable names. Minitab interprets the second line as a command because MIN and MAX are also Minitab commands. It displays the error message because it thinks you are trying to execute a command without first having entered the required END statement. You must avoid using Minitab commands for variable names if you need to use them in this way.

Variable types

There are four special-purpose variables, which are each declared differently:

Subcommand: An implicit constant that has a value of either 1 (if the subcommand was invoked) or 0 (if the subcommand was not invoked)

Text: Declared with MCONSTANT as a text constant that contains a text string

Suffixed: Declared with MCOLUMN or MCONSTAN as a range of columns or constants

Free: Declared with MFREE as a column, constant, or matrix whose type is undetermined until the macro is invoked