Using Execs. MINITAB User s Guide

Pages 12
Views 14

Please download to get full document.

View again

of 12
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Description
33 Using Execs What Is an Exec?, 33-2 How Execs are different from global and local macros Converting Execs to %Macros, 33-3 To convert your Exec to a global macro; To convert your Exec to a local macro;
Transcript
33 Using Execs What Is an Exec?, 33-2 How Execs are different from global and local macros Converting Execs to %Macros, 33-3 To convert your Exec to a global macro; To convert your Exec to a local macro; Commands that work differently in %macros How to Create an Exec, 33-4 Simple Example of an Exec, 33-4 Running an Exec, 33-5 Creating Loops, 33-5 Looping through commands; Looping through columns and matrices Using Conditional Execution and Nesting Execs, 33-7 Handling a Variable Number of Arguments, 33-8 Making Execs Interactive, 33-8 Pausing for input; Getting yes or no answers from a user, Example of YESNO Using STARTUP Macros and Execs, Displaying Commands in the Session Window, NOECHO/ECHO suppresses/restores the echo printing of MINITAB commands MINITAB User s Guide Chapter 33 What Is an Exec? What Is an Exec? Execs are stored commands that you will use over and over, so you do not have to retype them each time. You can even write an interactive Exec, which pauses during execution, prompts the user for information, then continues with execution. Execs, like global and local macros (see below), are useful for many things: repeating a block of commands many times useful for simulations looping through columns of the worksheet, doing the same analysis on each block of columns looping through rows of the worksheet, doing the same analysis on each block of rows performing complex operations not provided as stand-alone commands How Execs are different from global and local macros Earlier releases of MINITAB supported only Execs. MINITAB now has a more robust programming language that allows you to create global and local macros, sometimes grouped under the term %macros. %Macros are more powerful and flexible than Execs. Here are some of the other differences: Type Have a default file extension of Invoked by Exec MTB Typing the command EXECUTE or by choosing Files Other Files Run an Exec %Macro MAC Entering the symbol % followed by the macro file name: for example, %SALES invokes the macro SALES.MAC Documented in This chapter Chapters If you have Execs that were written using previous releases of MINITAB, you may continue to use them with no change unless, of course, the Execs use obsolete commands (see the note below). If you are writing a new macro, we recommend you write it as a %macro, because we may phase out Execs in a future release of MINITAB and because the new macros provide much greater power and flexibility than do Execs. If you would like to convert your Execs to global or local macros, it is very easy to do; see Converting Execs to %Macros on page Note MINITAB no longer supports the old high-resolution graph commands such as GPLOT and GHISTOGRAM. If your macros include these commands, you need to delete them or replace them with the new versions of those commands (for example, PLOT and HISTOGRAM) in order for your macros to work MINITAB User s Guide 1 Converting Execs to %Macros Using Execs Converting Execs to %Macros To convert your Exec to a global macro 1 Add three lines to your Exec file: GMACRO as the first line, ENDMACRO as the last line, and the template (the macro name) as the second line of the file. See Creating a Macro on page 28-4 for details. 2 Check for MINITAB commands that work differently in %macros (below). 3 Save the macro as a text file, with the extension MAC. Once you have converted your Exec to a global macro, you can incorporate any of the features documented in the chapters for global macros such as DO-loops and IF statements. You can also include several macros, or subroutines, in one macro file. To convert your Exec to a local macro Read the information on local macros presented in Chapters Local macros do not support the CK capability (for information that capability, see Using Conditional Execution and Nesting Execs on page 33-7). If your Exec uses the CK syntax, replace that with the appropriate control statement from Chapter 30. Commands that work differently in %macros Execs allow a repeat factor, such as 3 in the command EXECUTE MYMACRO 3. Global macros do not allow a repeat factor because they allow control statements such as DO-loops and WHILE statements which work much more efficiently. If your Exec requires such a repeat factor, you will need to incorporate that operation within the body of the global macro. In earlier releases of MINITAB, the default was ECHO. Now the default is NOECHO, which means that commands are not normally displayed while the macro executes. If your Exec contains NOECHO commands, there is no harm in leaving them there, but they may not be necessary anymore. READ, SET, and INSERT commands should follow these conventions: If the command reads data from a file, you must modify the command so that the file name is listed with a FILE subcommand, rather than being listed on the main command line. If the command is followed by data, you must include the statement END at the end of the data, on its own line. MINITAB User s Guide Chapter 33 How to Create an Exec If the command is followed by a FORMAT subcommand followed by data, the END statement must begin at the beginning of the line. If END is indented at all, MINITAB will not recognize it and you will get an error message. How to Create an Exec There are two ways to create Execs: 1 With a text editor or word processor. If you use an editor, store the file in a text format. If you use a word processor, make sure you save the file as a text file not the native format of the word processor. For example, if you are using Microsoft Word, do not save as a Word file, but choose File Save As and select a file type of Text only. Save the file with the extension MTB; that way, when you use the EXECUTE command, you will not have to type the extension because MINITAB will assume the file has the default extension of MTB. 2 With the command JOURNAL, described in Help. JOURNAL stores a copy of all commands used in a MINITAB session in a file with the extension MTJ. Note that when you EXECUTE the file, you must use the extension MTJ. Simple Example of an Exec Each month, a laboratory sends you data on three chemical measurements: Yield, Chem1, and Chem2. You always do the same analysis: descriptive statistics, plots of Yield versus the two other measures, a regression, and a residual plot. Suppose you use your computer s editor to create the following file called ANALYSIS.MTB: NAME C1='Yield' C2='Chem1' C3='Chem2' DESCRIBE C1-C3 PLOT C1*C2 PLOT C1*C3 REGRESS C1 2 C2 C3 C10 C11 NAME C10 = 'Resids' C11 = 'Fits' PLOT C10 C11 Then, if you put the data for January in the file JAN.MTW, you can perform your analysis by doing the following: 1 Choose File Open Worksheet and select JAN.MTW. 2 Choose File Other Files Run an Exec. Click Select File. 3 Select ANALYSIS.MTB. Click Open MINITAB User s Guide 1 Running an Exec Using Execs Running an Exec File Other Files Run an Exec EXECUTE [ filename ] [K times] Executes commands that have been stored in a file. These command files are called Execs. The default file extension for Execs is MTB. When using EXECUTE, you do not need to type the file extension if it is MTB. The default file name is MINITAB.MTB if you do not specify a file name with EXECUTE, MINITAB looks for the file MINITAB.MTB and runs the file if it exists. The optional argument K lets you specify how many times to run the Exec. K can be any integer. The default value is one, which means that the macro will be executed one time. If K 1, the macro is executed K times. If K 0, the macro is not executed. To interrupt the execution of an Exec, press c+k. MINITAB will finish executing the command in process before it stops the macro. Creating Loops Looping through commands We ll start with a simple example. Suppose you want to train your eye to judge normal probability plots. So you decide to generate 20 plots for data from a normal distribution. First store the following commands in a file called NPLOT.MTB: RANDOM 50 C1 NSCORES C1 C2 NAME C1='Data' C2='Nscores' PLOT C1*C2 To execute this file 20 times, to get 20 different normal probability plots, type EXECUTE NPLOT 20 You can also loop through rows of data. Suppose we have a full year of the laboratory data from our first example, one month stacked on top of another, in a file called LAB.DAT. There are now four variables, Yield, Chem1, Chem2, and Month. To do the same analysis as before, separately for each month, we store the following commands in the file YEAR.MTB: NAME C11='Yield' C12='Chem1' C13='Chem2' C20='Resids' C21='Fits' MINITAB User s Guide Chapter 33 Creating Loops COPY C1-C3 C11-C13; USE C4 = K1. PRINT K1 DESCRIBE C11-C13 PLOT C11*C12 PLOT C11*C13 REGRESS C11 2 C12 C13 C20 C21 PLOT C20*C21 ADD K1 1 K1 Then, to analyze the file LAB, we type LET K1 = 1 READ LAB C1-C4 EXECUTE YEAR 12 Looping through columns and matrices A special feature, sometimes called the CK capability, allows you to loop through columns of the worksheet. Suppose you have a file, MYDATA.DAT, containing 21 variables and you want to plot the last variable versus each of the first twenty variables. That s twenty separate plots. First store the following commands in a file called PLOTS.MTB: PLOT C21*CK1 ADD K1 1 K1 Then type READ MYDATA C1-C21 LET K1 = 1 EXECUTE PLOTS 20 The first time through the loop, K1 = 1. This value is substituted for the K1 in the PLOT command, giving PLOT C21 C1. The next time through the loop, K1 = 2, giving PLOT C21 C2, and so on. Matrices also have this capability, using MK1. Stored constants do not. The next example shows how to accumulate column statistics in one column. Suppose you have data in C1 through C30 and you want to compute the mean of each column and store those means in C40. Store the following commands in the file MEAN.MTB: LET C40(K1) = MEAN (CK1) ADD K1 1 K1 Then type LET K1 = 1 EXECUTE MEAN 30 The first time through the loop K1 = 1, so row 1 of C40 will equal the mean of C1. The next time through the loop K1 = 2, so row 2 of C40 will equal the mean of C2, and so on MINITAB User s Guide 1 Using Conditional Execution and Nesting Execs Using Execs Note The CK capability works in global macros, documented in Chapter 28, but not in local macros, documented in Chapter 29. In global and local macros, the macro statements such as DO and WHILE, documented in Chapter 30, are more powerful than the CK capability. Using Conditional Execution and Nesting Execs If the argument K on EXECUTE is zero or negative, the Exec is not executed. This feature allows you to do conditional execution. As an example, we will modify the Exec MEAN.MTB so that it accumulates means for just those columns that have more than 9 observations. We need two files. MEAN10.MTB contains: LET K3 = (COUNT(CK1) 9) EXECUTE OVER9 K3 ADD K1 1 K1 and OVER9.MTB contains LET C40(K2) = MEAN(CK1) ADD K2 1 K2 To use this macro, we type LET K1 = 1 LET K2 = 1 EXECUTE MEAN10 30 First, notice that we have nested two Execs, that is, MEAN10 calls (or executes) OVER9. Nesting helps you write fairly sophisticated Execs. You can nest up to five deep on most computers. To see how this macro works, we will look at the first three columns. Suppose C1 has 23 observations, C2 has 7, and C3 has 35. When we first execute MEAN10, K1 = K2 = 1. Then K3 = 1 since COUNT (C1) 9. Since K3 = 1, OVER9 is executed once, MEAN (C1) is stored in row 1 of C40, and K2 = 2. For the second time through the loop, K2 = 2 and K1 = 2. This time K3 = 0 since COUNT (C2) 9, and OVER9 is not executed. For the third time through the loop, K1 = 3 and K2 = 2. Then K3 = 1 since COUNT (C3) 9, OVER9 is executed, and MEAN (C3) is stored in row 2 of C40. MINITAB User s Guide Chapter 33 Handling a Variable Number of Arguments Handling a Variable Number of Arguments Sometimes you do not know how many columns of data will be used in each analysis; one time you may need the exec to operate on 10 columns, and the next time on 12 columns. The CK capability described above also allows you to write an exec that can operate on a variable number of columns. Again, we will explain using an example. Each month a researcher collects data from tomato plants. Some months she has 20 plants, other months just 5. The data for one month consist of one variable for each plant. First she creates the following Exec, called PLANTS.MTB: HISTOGRAM C1-CK50 DESCRIBE C1-CK50 ADD K50 50 K51 COPY C1-CK50 C51-CK51 (etc.) Then, if she has data on 12 plants, she types READ C1-C12 (data) END LET K50 = 12 EXECUTE PLANTS Making Execs Interactive Pausing for input It is possible to write an Exec which will execute, pause for user input, and then continue executing. This is accomplished by using the special file name TERMINAL with the READ, SET, and INSERT commands. Here is an example. We have two Execs. The first, PLANTS.MTB, is the same as before. The second, TOMATO.MTB, contains NOTE How many tomato plants do you have this month? SET C50; FILE TERMINAL ; NOBS = 1. COPY C50 K50 EXEC PLANTS When you type EXECUTE TOMATO , the note How many tomato plants do you have this month? is printed. The terminal then waits for you to respond. You type a number and press e. The subcommand NOBS = 1 tells SET to expect just one number. This means the user of the macro does not have to type the word END to signal the end of typing data to SET. The macro TOMATO is then executed with the 33-8 MINITAB User s Guide 1 Making Execs Interactive Using Execs correct number of plants. (The YESNO command, described on page 33-9, also takes input from the keyboard.) Note If you use READ, SET, or INSERT with the subcommand FILE TERMINAL while command language is turned off in the Session window (with the menu command Editor Disable Command Language), an error message will be displayed and the Exec will stop. The command NOECHO suppresses the echo printing of commands, and ECHO turns it back on. These are also described later in this chapter. Getting yes or no answers from a user YESNO K Prompts the user for a decision to execute or skip a block of commands. YESNO reads a YES or NO response from the terminal and changes the value of its argument, K, accordingly. YESNO sets K = 1 when the user responds YES, and K = 0 when the user responds NO. YESNO takes only one argument and it must be a stored constant. Any response beginning with an upper or lower case Y is interpreted as a YES; any beginning with an upper or lower case N is interpreted as NO. All other responses are invalid. The user receives the message Please answer Yes or No and is given another opportunity to enter an acceptable answer. If a valid response is not obtained after five tries, a NO answer is assumed. YESNO does not issue a prompt; it only reads a response. The Exec writer must use the NOTE command to prompt the user for a response. Note If you use YESNO while command language is turned off in the Session window (with the menu command Editor Disable Command Language), an error message will be displayed and the Exec will stop. The SET command also accepts a response from the user of an Exec. This is described under Making Execs Interactive on page e Example of YESNO This example involves one main Exec, TREE, and four Execs that are called by the main one. SubExec1 contains just one line, DOTPLOT 'Diameter'. SubExec2 contains just one line, DOTPLOT 'Height'. And SubExec3 contains just one line, DOTPLOT 'Volume'. This example shows an example of running TREE. MINITAB User s Guide Chapter 33 Making Execs Interactive TREE Exec that uses YESNO # Reads in tree data and prompts the user for dotplots RETRIEVE TREES # NOTE We will look at data on 31 black cherry trees. NOTE There are three variables: diameter, height, and volume. NOTE NOTE Here are descriptive statistics on the three variables. DESCRIBE C1-C3 NOTE Would you like to see a dotplot of diameter? YESNO K1 EXECUTE SubExec1 K1 NOTE NOTE Would you like to see a dotplot of height? YESNO K2 EXECUTE SubExec2 K2 NOTE NOTE Would you like to see a dotplot of volume? YESNO K3 EXECUTE SubExec3 K3 The example shows output that would result if the user invoked the Exec, then answered No to the first two requests and Yes to the last request. 1 Choose File Other Files Run an Exec. 2 Click Select File. 3 Type TREE in File Name. Click OK. Session window output We will look at data on 31 black cherry trees. There are three variables: diameter, height, and volume. Here are descriptive statistics on the three variables. Descriptive Statistics Variable N Mean Median TrMean StDev SEMean Diameter Height Volume Variable Min Max Q1 Q3 Diameter Height Volume Would you like to see a dotplot of diameter? NO Would you like to see a dotplot of height? NO MINITAB User s Guide 1 Using STARTUP Macros and Execs Using Execs Would you like to see a dotplot of volume? YES Executing from file: SUBEXEC3.MTB Character Dotplot. :. :...:::.:.. :... : : Volume Using STARTUP Macros and Execs STARTUP.MAC and STARTUP.MTB are special macro files you can create, either of which is automatically executed every time you start or restart MINITAB. They are handy tools for users who wish to avoid typing the same commands every time they start a MINITAB session. Users of earlier versions of MINITAB may have an Exec file named STARTUP.MTB. If you are going to write a new startup macro, we suggest writing it as STARTUP.MAC. STARTUP.MAC can be a global or local macro. See chapters for information on global and local macros. When you start or restart MINITAB, MINITAB looks for macro files in the order shown below, and executes the first one it finds, if one exists. In your current directory In the \MACROS subdirectory of the main MINITAB directory STARTUP.MAC STARTUP.MTB STARTUP.MAC STARTUP.MTB Create a STARTUP.MAC or STARTUP.MTB file as you would any other macro or Exec, with a text editor or word processor. The file must be called STARTUP.MAC or STARTUP.MTB. Possible applications of the startup file include: setting up an OUTFILE or JOURNAL setting switches (BRIEF, OH, OW) setting up graphics options (GPRO, GSTD) automatically RETRIEVE a saved worksheet sending users messages via the NOTE command MINITAB User s Guide Chapter 33 Displaying Commands in the Session Window Displaying Commands in the Session Window ECHO the commands that follow NOECHO the commands that follow (default) Controls whether or not commands in an Exec are displayed in the Session window. By default, NOECHO is in effect. When you EXECUTE a file, the commands are not printed (echoed) on the output. Only output and the comments on NOTE commands (see NOTE in Chapter 31) will be printed. Comments after the # symbol will not be printed. When you want to turn on echo printing of commands use ECHO. You can type ECHO and NOECHO in the session window before you invoke a macro or place them anywhere within the body of a macro. You can use ECHO and NOECHO several times in a macro to turn echo display on and off MINITAB User s Guide 1
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks
SAVE OUR EARTH

We need your sign to support Project to invent "SMART AND CONTROLLABLE REFLECTIVE BALLOONS" to cover the Sun and Save Our Earth.

More details...

Sign Now!

We are very appreciated for your Prompt Action!

x