Minitab Macros
Usually Minitab is used by typing commands in the Session window or by selecting menus and completing dialog boxes. Alternatively, one can employ Minitab macros. A Minitab macro consists of a sequence of Minitab commands and macro statements stored in a text file. Typically, a Minitab macro is used to automate a repetitive task, extend the functionality of Minitab, or perform simulations.
Presently Minitab supports three types of macros: execs, global macros, and local macros. Execs are an older form of macro and may be phased out in future versions of Minitab; global and local macros are newer and much more versatile and powerful than execs. Global and local macros macros are referred to collectively as %macros, because they are invoked in the Session window by typing a percent sign followed by the name of the macro file.
Both global and local macros can contain Minitab commands, macro statements such as DO-loops and IF-statements to control macro flow, and subroutines. But local macros have several advantages over global macros such as the ability to use arguments, local variables, and their own subcommands.
In this paper we will concentrate on local macros. Included will be a discussion of:
Global and local worksheets
Structure of a local
macro
Extending Minitab with
local macros for data analysis
Extending Minitab with
local macros for inference
Extending Minitab with
local macros for simulation
Global and Local Worksheets
In Minitab there is a worksheet, called the global worksheet, containing all columns, constants, and matrices. This is the worksheet on which (regular) Minitab acts; it is also the worksheet on which global macros act.
On the other hand, each local macro acts on a worksheet of its own, called its local worksheet. Thus a local macro has its own columns, constants, and matrices that are separate from those in the global worksheet. Manipulating the local variables has no effect on the global worksheet except, as we will see later, for those variables that have been passed to the local macro as arguments. After a local macro is exited, all of its variables disappear.
Structure of a Local Macro
Local macros have a specific structure as indicated below:
MACRO
template
declaration statements
body of the macro
ENDMACRO
MACRO and ENDMACRO mark, respectively, the beginning and end of the macro; but keep in mind that a given file can contain more than one macro.
The template consists of the macro command name, subcommands (if any), and arguments (if any). The declaration statements are used to identify variables and their types (column, constant, matrix, or free); all variables used in a local macro must be declared in the declaration statements. The body of the macro contains the desired Minitab commands, macro statements, and calls to subroutines and other macros.
Extending Minitab With Local Macros for Data Analysis
Following is GRADE, a local macro that is used to convert numerical grades to letter grades. We will use GRADE to illustrate the structure of a local macro and additional features such as regular and suffixed variables, arguments, comments, notes, controlling macro flow, and interaction with the user. The line numbers are for reference only; that is, they are not part of the macro file.
01 # GRADE.MAC
02 #
03 # Converts numerical grades to letter grades and supplies
graphics
04 #
05 # Macro is for MINITAB for Windows, release 11 and above
06 # Written by: Neil A. Weiss
07 # Date: 10/17/96
08
09 # To run this macro, type "%GRADE <COL1> <COL2>"
where <COL1> is
10 # the column containing the numerical grades and <COL2>
is the
11 # column to contain the letter grades.
12
13 MACRO
14
15 GRADE I O
16
17 MCOLUMN S B C I O N L T D.1-D.3
18 MCONSTANT f min.1-min.5 max.1-max.5 ans
19
20 NOTE
21 NOTE This macro converts numerical grades to letter grades
using
22 NOTE the grading scale that you specify, which can be total
points
23 NOTE or average points. The grade distribution is also provided.
24 NOTE
25 NOTE Enter the letter you use for a failing grade (e.g.,
F).
26 SET C;
27 FILE 'TERMINAL';
28 FORMAT (A1);
29 NOBS=1.
30 COPY C f
31 NOTE
32 NOTE Enter, by row, the smallest and largest numerical values
for
33 NOTE each grade, starting with those for an A. For example,
34 NOTE
35 NOTE 540 600
36 NOTE 480 539
37 NOTE 390 479
38 NOTE 330 389
39 NOTE 0 329
40 NOTE
41 NOTE Enter now!
42 NOTE
43 BRIEF 0
44 READ S B;
45 FILE 'TERMINAL';
46 NOBS=5.
47 COPY S min.1-min.5
48 COPY B max.1-max.5
49 READ N L;
50 FORMAT (F1,X,A1).
51 4 A
52 3 B
53 2 C
54 1 D
55 0 E
56 END
57 LET L(5)=f
58 CODE (min.1:max.1)4 (min.2:max.2)3 (min.3:max.3)2 &
59 (min.4:max.4)1 (min.5:max.5)0 I T
60 CONVERT N L T O
61 BRIEF 2
62 NOTE
63 NOTE Do you want the distribution of the letter grades?
64 YESNO ans
65 IF ans=0
66 EXIT
67 ENDIF
68 NAME D.1 'Grade' D.2 'Count' D.3 'Percent'
69 BRIEF 0
70 TALLY O;
71 COUNTS;
72 PERCENTS;
73 STORE D.1-D.3.
74 SORT D.1-D.3 D.1-D.3;
75 BY D.1.
76 BRIEF 2
77 PRINT D.1-D.3
78 NOTE
79 NOTE Do you want a graph of the distribution of the letter
grades?
80 YESNO ans
81 IF ans=0
82 EXIT
83 ENDIF
84 Chart D.3 * D.1;
85 Bar;
86 Type 1;
87 EColor 4;
88 Color 5;
89 Minimum 2 0;
90 Axis 1;
91 Label "Grade";
92 Axis 2;
93 Label "Percent".
94
95 ENDMACRO
Lines 1-7 are preceded by a number sign (#) to indicate that these lines are comments. Characters following a number sign do not display in the Session window and are ignored by the macro processor. Comments are useful for annotation and explanation. The blank line on Line 12 is for readability only, it too will not display in the Session window.
On Line 13 we find the word MACRO, signaling the beginning of the macro. Line 15 contains the template which, in this case, consists of the macro command name (GRADE) followed by two arguments, I and O. For this macro, the arguments are columns that will be passed to the macro from the global worksheet when the user types %GRADE <COL1> <COL2> in the Session window. Here <COL1> and <COL2> represent, respectively, the column that contains the numerical grades and the column that will contain the letter grades. These two columns will be passed back to the global worksheet.
Lines 17 and 18 contain the declaration statements which, in this case, declare several columns and constants. Among the declared columns are the suffixed columns D.1-D.3 and among the declared constants are the suffixed constants min.1-min.5 and max.1- max.5. Like a variable name, a suffix may contain up to eight characters and can be either an integer or a stored constant.
Next comes the body of the macro, from Lines 20-93. As we see, several lines begin with NOTE. The text following NOTE will display in the session window but will be ignored by the macro processor. Such lines are invaluable for communicating with the user to supply information or solicit user input.
Some other lines of interest are: Lines 25-30 request information from the user (the letter used for a failing grade) and store the user’s response in the constant f. On Lines 63-67 the user is asked whether he or she wants the grade distribution; if not, the macro exits. And, finally, on Line 95 we have ENDMACRO, signaling the end of the macro.
Now we will run the GRADE macro and see it in action. First set up your computer as described in preictcm.htm. Then proceed as follows:
Click the link GRADE
at the end of this sentence, choose File > Save As..., save the
file in your Minitab's directory for macros (e.g., \mtbwin\macros)
as grade.mac, and then click the Back button. GRADE
Click here
to start Minitab.
Store the numerical
grades you want to convert to letter grades in a column of your choice.
Type %GRADE <COL1>
<COL2>, where <COL1> and <COL2>
are, respectively, the column that contains the numerical grades and the
column that will contain the letter grades.
Follow the instructions
generated by the macro.
Extending Minitab With Local Macros for Inference
In addition to writing data-analysis macros like GRADE, we can also construct local macros to extend Minitab’s capabilities for inference.
As an example, we will consider the macro FITTEST. This macro performs a chi-square goodness-of-fit test on data supplied by the user. Note that the macro checks to ensure that the conditions for using that test are met; if they are not, a warning is issued. For our example, we will use the data on the specialty distribution of U.S. physicians given in Example 12.4 on page 691 of Introductory Statistics, Fourth Edition, Alternate Version Featuring MINITAB for Windows. Click here to begin.
Extending Minitab With Local Macros for Simulation
We can also develop local macros for simulations to enhance student understanding of complex concepts such as the law of large numbers, probability distributions, the central limit theorem, and sampling distributions. To illustrate, we will run three macros: BORELLLN, CORREL, and SIGLEVEL. These three macros provide simulations for illustrating, respectively, Borel's law of large numbers, correlation, and significance level. Click one of the following links to start Minitab and run the desired macro: BORELLLN; CORREL; SIGLEVEL.
References
MINITAB Reference Manual, Release 11 for Windows. State College, PA: Minitab Inc., June 1996.
Weiss, Neil A. Selected MINITAB Macros. ftp://math.la.asu.edu/pub/naweiss/mtbmacs.exe.
Weiss, Neil A. Introductory Statistics, Fourth Edition, Alternate Version Featuring MINITAB for Windows. Reading, MA: Addison-Wesley, 1997.