CALL, RETURN
    

CALL template

RETURN

You can include several macros in one file, just as a program often includes several subroutines. CALL and RETURN let you specify when to pass control to another macro and when to return to the main macro. You can include several global macros in one file, or several local macros in one file, but you cannot mix global and local macros together in one file.

When you invoke a macro, from interactive Minitab or from another macro, the first macro in the file is executed first. Use the macro statements CALL and RETURN to invoke a different macro within the macro file.

Recall that the second line of a macro is the template, or the macro name. When one macro in a macro file calls another macro in that file, use the command CALL, followed by the name on that macro's template. If it is a local macro, include appropriate arguments and subcommands. Any macro in a macro file can CALL any other macro in the file, any number of times.

RETURN says to leave the current macro and go back to the calling macro, to the statement just after the CALL. RETURN is optional. If RETURN is not present in the macro that was called (the subroutine), then after it has executed, control is transferred back to the calling macro.

The following example is a variation on ANALYZE2.MAC (see Invoking Macros from Within Macros) named ANALYZE3.MAC. This global macro file contains three macros:

GMACRO 

ANALYZE3 

#

NOTE Would you like all data printed?

YESNO K80 

# If user types "yes" K80 = 1, if "no" K80 = 0

LET K90 = COUNT(C1) 

IF K90 < 5 

  CALL TOOSMALL

ELSE 

  CALL OK 

ENDIF 

#

IF K80 = 1

NOTE Here are the data.

PRINT C1-C3

ENDIF

ENDMACRO 

#

#

GMACRO 

TOOSMALL 

NOTE Data set has fewer than 5 observations. 

NOTE No analysis will be done.

ENDMACRO 

#

#

GMACRO 

OK 

NAME  C1 = 'Yield' C2 = 'Chem1'  C3 = 'Chem2' C5 = 'Ln.Yield' 

DESCRIBE C1-C3

LET C5 = LOGE('Yield') 

REGRESS C5 2 C2 C3 

IF K80 = 1

  RETURN

ENDIF

NOTE Analysis done, but no data printed by request

ENDMACRO

In this example, ANALYZE3, we use the YESNO command (see Getting Yes or No Answers From a User) to see if the user wants to print all the data. If the response is "Yes," YESNO sets K80 to 1; if the answer is "No," K80 is set to 0.

The OK subroutine checks the value of K80 with an IF statement. If K80 equals 1, the RETURN statement sends control back to the main macro. If K80 is anything else, the macro prints one more note.

When the ENDMACRO statement is encountered in either the TOOSMALL or OK subroutine, control is transferred back to the calling macro.