What is a macro?

A macro is a text file that contains a series of Minitab session commands. You can use macros to automate a repetitive task (for example, generating a monthly report) or to extend Minitab's functionality (for example, computing a special test statistic).

The following types of macros are available in Minitab:
Global macros (.MAC files)
Allow you to analyze and manipulate data in the active worksheet. However, the identity of any columns, constants, and matrices that are to be accessed must be specified within the macro; therefore, the worksheet must be configured the same way each time the macro is run.
GMACRO 
NOMISS    
LET K90 = COUNT('X') 
DO K91 = 1:K90 
  IF  'X'[K91] = '*' 
  DELETE  K91:K90 'X' 
    BREAK 
  ENDIF 
ENDDO 
ENDMACRO
Example

This macro (NOMISS) looks for the first missing observation in a column named X, then deletes the remainder of the column.

Local macros (.MAC files)
More powerful and flexible than global macros because they can accept arguments and have their own subcommands. Users specify the data to be processed when they run the macro, making the data setup more flexible. However, local macros are also more complicated to write than global macros.
MACRO 
MNSTD x y z 
MCOLUMN x y z v 
MCONSTANT N i k1 k2 
MRESET 
BRIEF 0 
LET N=count(x) 
LET y(1)='*' 
LET z(1)='*' 
DO i=2:N 
COPY x v; 
USE 1:i. 
LET y(i)= MEAN(v) 
LET z(i)= STDEV(v) 
ENDDO 
ENDMACRO

Example

This macro (MNSTD) calculates the mean and standard deviation for the first two rows of a column, then the first three rows, and so on.

Exec files (.MTB files)
A simpler form of Minitab macro; execs cannot have control statements or accept arguments and subcommands when run. Exec files can be useful if you want to rerun a series of commands you just ran; for example, to recreate a graph you made earlier in your Minitab session. Simply highlight the commands in Minitab's History window and save them as an exec file.
HISTOGRAM C1 C2;
    YFrequency;
    Bar;
    Panel.
Example

This exec draws a histogram of frequency for two columns and panels them.

How do I create an Exec (.MTB file) to automate a series of procedures I often run in Minitab?

The easiest way to create an exec file is to save command language from the History folder.

  1. Run the commands that you want the Exec file to contain.
  2. Press CTRL+ALT+H to open the History folder.
  3. Select the commands that you want to include in the Exec file.
  4. In the right pane, right-click and choose Save As.
  5. In File name, enter the desired name (for example, TEST.MTB).
  6. From the Save as type list, choose Exec Files (*.MTB). Click Save.

How do I run an Exec (.MTB file) to automate a series of procedures I often run in Minitab?

  1. Choose Tools > Run an Exec.
  2. Specify the Number of times to execute your exec.
  3. Click Select File.
  4. Click the desired file (for example, TEST.MTB). Click Open.
    Tip

    To run an Exec, you could also drag and drop the Exec file on a Minitab shortcut.

Can I use ODBC (Open Database Connectivity) in a macro?

Yes. The COLUMNS subcommand is required in local macros. COLUMNS specifies which columns of the Minitab worksheet should hold the data. In global macros or exec files, executing the ODBC command without the COLUMNS subcommand places new data at the end of the global worksheet.

By using this site you agree to the use of cookies for analytics and personalized content.  Read our policy