Introduction to Minitab Macros. Types of Minitab Macros. Objectives. Local Macros. Global Macros



Similar documents
Creating a Simple Macro

Unix Shell Scripts. Contents. 1 Introduction. Norman Matloff. July 30, Introduction 1. 2 Invoking Shell Scripts 2

Symbol Tables. Introduction

DATA 301 Introduction to Data Analytics Microsoft Excel VBA. Dr. Ramon Lawrence University of British Columbia Okanagan

Introduction to Matlab

Basics of STATA. 1 Data les. 2 Loading data into STATA

CNT5106C Project Description

Pseudo code Tutorial and Exercises Teacher s Version

Lecture 2 Mathcad Basics

Microsoft Access 2010 Part 1: Introduction to Access

MOVES Batch Mode: Setting up and running groups of related MOVES run specifications. EPA Office of Transportation and Air Quality 11/3/2010

Importing Excel File using Microsoft Access in SAS Ajay Gupta, PPD Inc, Morrisville, NC

Chapter 5 Programming Statements. Chapter Table of Contents

MATLAB Functions. function [Out_1,Out_2,,Out_N] = function_name(in_1,in_2,,in_m)

Debugging. Common Semantic Errors ESE112. Java Library. It is highly unlikely that you will write code that will work on the first go

Xcode User Default Reference. (Legacy)

Labels, Labels, and More Labels Stephanie R. Thompson, Rochester Institute of Technology, Rochester, NY

Microsoft Windows PowerShell v2 For Administrators

Minitab Session Commands

Simple File Input & Output

1 Description of The Simpletron

Oracle Forms Services Secure Web.Show_Document() calls to Oracle Reports

MATLAB Tutorial. Chapter 6. Writing and calling functions

Windows PowerShell Essentials

Excel & Visual Basic for Applications (VBA)

Programming Languages CIS 443

CLC Server Command Line Tools USER MANUAL

Version 1.5 Satlantic Inc.

Macros in Word & Excel

Appendix K Introduction to Microsoft Visual C++ 6.0

HP-UX Essentials and Shell Programming Course Summary

How to test and debug an ASP.NET application

Librarian. Integrating Secure Workflow and Revision Control into Your Production Environment WHITE PAPER

Using CPLEX. =5 has objective value 150.

PharmaSUG Paper QT26

Applications Development

PageR Enterprise Monitored Objects - AS/400-5

Appendix: Tutorial Introduction to MATLAB

Data Integrator. Pervasive Software, Inc B Riata Trace Parkway Austin, Texas USA

A Computer Glossary. For the New York Farm Viability Institute Computer Training Courses

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

SAS Analyst for Windows Tutorial

Code::Blocks Student Manual

Basic C Shell. helpdesk@stat.rice.edu. 11th August 2003

Hypercosm. Studio.

Backing Up TestTrack Native Project Databases

Bitrix Site Manager 4.0. Quick Start Guide to Newsletters and Subscriptions

Forms Printer User Guide

grep, awk and sed three VERY useful command-line utilities Matt Probert, Uni of York grep = global regular expression print

Combining SAS LIBNAME and VBA Macro to Import Excel file in an Intriguing, Efficient way Ajay Gupta, PPD Inc, Morrisville, NC

Stored Documents and the FileCabinet

Before You Begin... 2 Running SAS in Batch Mode... 2 Printing the Output of Your Program... 3 SAS Statements and Syntax... 3

DiskPulse DISK CHANGE MONITOR

Demonstrating a DATA Step with and without a RETAIN Statement

PYTHON Basics

An Introduction to Assembly Programming with the ARM 32-bit Processor Family

Hands-on Exercise 1: VBA Coding Basics

Oracle Database: Develop PL/SQL Program Units

CS 241 Data Organization Coding Standards

A QUICK OVERVIEW OF THE OMNeT++ IDE

Figure 1: Graphical example of a mergesort 1.

Windows Server 2003 Logon Scripts Paul Flynn

Data analysis and regression in Stata

Creating a Guest Book Using WebObjects Builder

Chapter 7: Additional Topics

MXwendler Javascript Interface Description Version 2.3

MAS 500 Intelligence Tips and Tricks Booklet Vol. 1

Sources: On the Web: Slides will be available on:

Simply Accounting Intelligence Tips and Tricks Booklet Vol. 1

Microsoft Office 2010: Access 2010, Excel 2010, Lync 2010 learning assets

Search and Replace in SAS Data Sets thru GUI

Hands-On UNIX Exercise:

How to Use SDTM Definition and ADaM Specifications Documents. to Facilitate SAS Programming

Tips and Tricks SAGE ACCPAC INTELLIGENCE

I PUC - Computer Science. Practical s Syllabus. Contents

SAS 9.4 Logging. Configuration and Programming Reference Second Edition. SAS Documentation

Microsoft Office. Mail Merge in Microsoft Word

SAS 9.3 Logging: Configuration and Programming Reference

A Crash Course on UNIX

KB_SQL SQL Reference Guide Version 4

TestManager Administration Guide

Microsoft Excel 2010 Part 3: Advanced Excel

FIGURE Selecting properties for the event log.

AN ANIMATED GUIDE: SENDING SAS FILE TO EXCEL

CSC 120: Computer Science for the Sciences (R section)

Introduction. Why Use ODBC? Setting Up an ODBC Data Source. Stat/Math - Getting Started Using ODBC with SAS and SPSS

Animated Lighting Software Overview

Shell Scripts (1) For example: #!/bin/sh If they do not, the user's current shell will be used. Any Unix command can go in a shell script

Dynamic Web Pages for EnviroMon

Settings 1 September 2015

Using the ihistorian Excel Add-In

Tutorial 2: Reading and Manipulating Files Jason Pienaar and Tom Miller

VB.NET Programming Fundamentals

Using the JNIOR with the GDC Digital Cinema Server. Last Updated November 30, 2012

Review your answers, feedback, and question scores below. An asterisk (*) indicates a correct answer.

MATLAB Programming. Problem 1: Sequential

Scripts and functions

Transcription:

Minitab Macros 10.1 Introduction to Minitab Macros 10.2 Global Minitab Macros 10.3 Local Minitab Macros 10.4 Advanced Minitab Macro Programming 10.5 Hints on Debugging Macros Introduction to Minitab Macros Objectives Identify the three different types of Minitab macros. Describe the characteristics of the three types of macros. Types of Minitab Macros Global Macro simplest form of a Minitab Macro Local Macro advanced form of Minitab Macro Execs older form of Minitab Macro Global Macros Apply directly to the columns of the current worksheet, matrices and constants. Must be stored in a file. Can include any Minitab session commands. Can include some control statements. Does not accept any arguments or subcommands. Relatively easy to define, but the lack of structure often results in unintended consequences. Local Macros Executes locally, requires local variables to be defined. Must be stored in a file. Can include any Minitab session commands. Can include a variety of control statements. Calls to the Macro can include arguments and/or subcommands. Very flexible, but requires more precise programming.

Execs Oldest form of Minitab Macros. Must be stored in a file. Can include any Minitab session commands. Control statements are not available. Calls to the Exec can imply iterative looping. Executes similar to a Global Macro. Generally considered obsolete, but still in use. Not recommended by Minitab, will not be covered any more in this course. Global Minitab Macros Objectives Define the structure of a Minitab global macro. Illustrate the use of a Minitab global macro with an example. The Structure of a Global Macro GMACRO template body of the macro ENDMACRO GMACRO marks the beginning of the macro. ENDMACRO marks the end of the macro. template the name of the macro. body of the macro Minitab commands, macro statements, and calls to other macros. Example of a Global Macro As stored in the file gmacroex1.mac: GMACRO beginning of macro gmacroex1 template name of macro Random k1 c1; Normal 500 100. body of macro Minitab commands Histogram c1. ENDMACRO end of macro Note 1: This macro requires that k1 be already defined as an integer greater than 1; otherwise the macro will produce an error. Note 2: This macro will overwrite any data that currently resides in column one. Creating and Storing a Global Macro Create a file with a simple editor, such as Notepad. Copy/paste commands from Minitab s Project Manager s History. Add GMACRO, a macro name, and ENDMACRO. Other Hints: Use the same name for the macro as the filename. Use the default extension.mac Be sure to switch to all files when using the SAVE AS TYPE in Notepad; otherwise your file may be named myfile.mac.txt rather than myfile.mac Store the macro in the /MACROS subdirectory of the Minitab Program if you plan to use it often.

Invoking a Global Macro To execute the macro, type: % fullmacroname where fullmacroname is the complete path and name of the macro to be executed. Example: %'C:\My Documents\cqas742\Class 10\gmacroex1.mac Invoking a Global Macro Example: %'C:\My Documents\cqas742\Class 10\gmacroex1.mac Notes: If the file extension is.mac, then it may be omitted. If the file is in the current directory, or in the /MACROS subdirectory of the Minitab Program, then the path may be omitted. If there are no spaces in the filename, of the path, then the single quotes may be omitted. Control Statements in a Global Macro Adding some control statements can make the macro more robust: IF, ELSEIF, ELSE, and ENDIF conditional statements. DO-ENDO statement blocks. CALL and RETURN access to other macros. WHILE-ENDWHILE loops. Adding messages to the user also help with execution: NOTE command to write to the session window. ECHO, NOECHO to control the display of commands. BRIEF 0 and BRIEF 2 to control the display of output from commands. GMACRO beginning of macro gmacroex2 template # checks the data type - 2 means integer # Brief 0 silences the output from the command Brief 0 Dtype k1 k98 # Turn output back on Brief 2 # If command makes sure that k1 is an integer # greater than zero, prints an error otherwise IF k1 < 1 Or K98 ~= 2 body Note K1 must be set to an integer greater than zero # Else is executed if everything is okay... ELSE Random k1 c1; Normal 500 100. Histogram c1. ENDIF As stored in the file: ENDMACRO end of macro lmacroex2.mac A Special Macro STARTUP.MAC STARTUP.MAC is executed whenever Minitab is started. Minitab will search the current directory, and the /MACROS subdirectory of the Minitab program. STARTUP.MAC can be a Global Macro, or a Local Macro. Commands that are might be put in STARTUP.MAC: OW Controls Output Width (Spaces/Line) OH Controls Output Height (Lines/Scrolling) NOTE Write messages to the session window RETRIEVE opens a saved worksheet BRIEF Controls Output from Commands Could be used to execute any predefined set of commands. Local Minitab Macros

Objectives Define the structure of a Minitab local macro. Illustrate the use of a Minitab local macro with an example. Introduce some of the more advance programming capabilities of the local macro. The Structure of a Local Macro MACRO template declaration statements body of the macro ENDMACRO MACRO marks the beginning of the macro. ENDMACRO marks the end of the macro. template the name of the macro. declaration statements defines all variables to be used. body of the macro Minitab commands, macro statements, and calls to other macros. Example of a Local Macro As stored in the file lmacroex1.mac: MACRO beginning of macro lmacroex1 ssize xbar sd template name of macro, arguments, and Mconstant ssize xbar sd subcommands declarations constants and columns Mcolumn sample Random ssize sample; Normal xbar sd. body of macro Minitab commands Histogram sample. ENDMACRO end of macro Note 1: This macro requires that three arguments are supplied when the local macro is called; otherwise it will produce an error. Note 2: This macro does not affect any data in the worksheet, but otherwise it produces the same type of plot as the global macro. Creating, Storing, and Invoking Global Macros The same rules apply to local macros: Created with a simple editor such as Notepad. Same conventions with regard to naming, and storing the macros. Macros are invoked, or called, the same way as local macros except that local macros can have arguments, and subcommands. Example: %'C:\My Documents\cqas742\Class 10\lmacroex1.mac 10 500 100 Arguments ssize xbar sd Variable Declarations All variables (constants, columns, or matrices) used in the local macro must be declared: MCONSTANT defines all the constants MCOLUMN defines all the columns Naming Variables A variable name Can be a maximum of eight characters. May include letters, numbers, and an underscore, but must begin with a letter. Can be in capitals, lower case, or mixed. Cannot be the same name as a subcommand. MMATRIX defines all the matrices The names of these variables do not have to follow the usual Minitab conventions (e.g. K for constants, C for columns, and M for matrices).

Adding Subcommands In order to add subcommands to a local macro, you must: Add a Subcommand Change the Template Template with a subcommand: Invoked by: 1) Add the subcommand to the template 2) Declare any additional variables needed lmacroex2 ssize xbar sd; Normaltest. %lmacroex2 10 500 100; Normaltest. 3) Add statements that conditionally execute dependent on the value of the subcommands. We ve added a subcommand named Normaltest, that requires no arguments Note: It is often easier to write the Minitab statements that make use of the subcommand, then write the declaration statements required Add a Subcommand Write the Statements MACRO beginning of macro lmacroex2 ssize xbar sd; Normaltest. Mconstant ssize xbar sd template name of macro, arguments, and subcommands declarations constants and columns Mcolumn sample Random ssize sample; Normal xbar sd. Histogram sample. body of macro Minitab commands If Normaltest ~= 0 %NormPlot sample Endif ENDMACRO end of macro Tests to see whether the subcommand was used Note: In this case no other variables were required, or declared Invoking a Local Macro with a Subcommand To execute the macro, type: % fullmacroname arguments; subcommands arguments. Example: %'C:\My Documents\cqas742\Class 10\lmacroex2.mac 10 500 100; Normaltest. Advanced Minitab Macro Programming Objectives Illustrate advanced macro programming by developing a local macro that takes samples from a column of data, calculates means, and outputs the results to a column of the same worksheet. Show how the macro is developed from the session commands.

Session Commands: Create the Data and Other Would-Be Arguments to the Macro # suppose c1 contains the data Random 100 c1; Normal 500 100. # k1 is the sample size let k1 = 25 # k2 is the number of samples let k2 = 5 Session Commands: Taking Random Samples with Replacement and Storing # take a random sample with replacement # store in columns c11-c15 (five samples) Sample K1 C1 c11; Sample K1 C1 c12; Sample K1 C1 c13; Sample K1 C1 c14; Sample K1 C1 c15; Session Commands: Calculating Sample Means and Storing Them # calculate the sample means and store in k11-k15 Mean C11 k11. Mean C12 k12. Mean C13 k13. Mean C14 k14. Mean C15 k15. # copy constants into a column c2 copy k11-k15 c2 Strategy Developed from the Session Commands The raw data column, the sample size, and the number of samples can be considered inputs to the macro. The output data column of sample means is the only required output from the macro. The samples can be temporary columns, and their means can be temporary constants (before they are copied to the output column). The number of temporary columns and constants is a function of the number of samples, and is not know until the macro is invoked, making it difficult to know how many variables to set aside in the declaration. The columns and constants would be more easily addressed if they behaved like SAS Arrays and sequenced variables (i.e. Sample1-Sample5) Developing the Macro - Template MACRO # template lmacroex3 ssize nsamples indata outmeans Developing the Macro Declarations # declarations Mconstant ssize nsamples Mcolumn indata outmeans # this macro does 5 samples, regardless # of the value of nsamples Mcolumn col11 col12 col13 col14 col15 Mconstant kon11 kon12 kon13 kon14 kon15

Developing the Macro - Sampling # take the random samples # would like to make this a loop Sample ssize indata col11; Sample ssize indata col12; Sample ssize indata col13; Sample ssize indata col14; Sample ssize indata col15; Developing the Macro - Calculations # calculate the sample means and store in kon11-kon15 # would like to make this a loop also Brief 0 Mean col11 kon11. Mean col12 kon12. Mean col13 kon13. Mean col14 kon14. Mean col15 kon15. Brief 3 Developing the Macro Return and End # copy constants into a column outmeans # variable number of constants... Copy kon11-kon15 outmeans ENDMACRO Invoking the Macro To execute the macro, type: %'C:\My Documents\cqas742\Class 10\lmacroex3.mac 10 5 C1 C2 Sample Size 10 Number of Samples 5 Input Data C1 Output Means C2 Note: This version of the macro produces five samples regardless of the value of the second argument. Improvements Still Needed We have to get the macro to execute the number of samples supplied in the call to the macro. In order to do this we must be able to: Declare a variable number of columns and constants depending on the value of nsamples. Loop through the samples as many times as specified by the value of nsamples. Reference a specific column or constant in a list as we go through the loop. Suffixed Variables Suffixed Variables (similar to SAS arrays), may be referred as: Suffixed Variable Variable Name Period Suffix sample.1 sample. 1 ` sample.index sample. index where index is a constant.

Do Loops DO Index =start : stop Minitab Statements ENDDO Refining the Macro - Template MACRO # template lmacroex4 ssize nsamples indata outmeans Do Loops with Suffixed Variables DO Index =start : stop Minitab Statements assignment = sample.index ENDDO Note: Only the macro name changed. Refining the Macro Declarations # declarations Mconstant ssize nsamples Mcolumn indata outmeans Mcolumn col.1-col.nsamples Mconstant kon.1-kon.nsamples index Refining the Macro - Sampling # take the random samples Do index = 1:nsamples Sample ssize indata col.index; Enddo Note 1: Now the number of columns and constants declared depends on the value of nsamples. Note: Several statements replaced with a loop Note 2: The variable index is added to the list of constants. Refining the Macro - Calculations # calculate the sample means and store in kon.index Brief 0 Do index = 1:nsamples Mean col.index kon.index Enddo Brief 3 Note: Several statements replaced with a loop Refining the Macro Return and End # copy constants into a column outmeans # variable number of constants... Copy kon.1-kon.nsamples outmeans ENDMACRO Note: Takes into account the variable number of samples

Objectives Introduce some Minitab commands that are useful in writing and debugging Minitab macros. Hints on Debugging Macros Interpreting Error Messages Errors are generally labeled with one of two designations: ** ERROR ** (two asterisks) means an error was found by the macro processor * ERROR * (one asterisk) means an error was found by regular Minitab Minitab Response to Macro Errors Minitab can stop when a macro error is found, or it can continue on through the program depending on the value of: PLUG NOPLUG - Minitab continues as best it can - Minitab stops when it encounters a macro error The default setting is NOPLUG, but the setting can be changed in the session window, or anywhere in the macro. Getting INFO During Macro Execution Syntax: INFO shows information about the local worksheet, including columns, constants and matrices. INFO can be typed in the session window to get information about the current active worksheet, or in the body of the macro to get information about the Local macro worksheet and it s temporary variables. Debugging Tools Minitab can stop when a macro error is found, or it can continue on through the program depending on the value of: ECHO NOECHO - Minitab commands are printed in the session log as executed by the macro processor - Minitab displays only the errors associated with the commands executed The default setting is NOECHO, but the setting can be changed in the session window, or anywhere in the macro.

Debugging Tools Minitab can printed additional diagnostic information during the macro processing depending on the value of: DEBUG - extra information is displayed Debugging Tools Minitab can pause execution of a macro at any point: PAUSE - execution is paused, and control is returned to the session window NODEBUG - no extra information is displayed RESUME - returns control to the macro The default setting is NODEBUG, but the setting can be changed in the session window, or anywhere in the macro. PAUSE can be place anywhere in the macro. When control is passed back, the user can type any command such as the PRINT command, or the INFO command. Note: The commands act only on the local macro worksheet. SUMMARY Minitab Global Macros can be defined to help automate repetitive tasks that act directly on the active worksheets. Minitab Local Macros can execute without modifying the active worksheet unless specified to do so. Minitab Local Macros can be written to accept arguments, and subcommands, making them much more flexible than Minitab Global Macros. Much of the capability of SAS Macros and SAS Arrays can be implemented within the context of Minitab Local Macros.