Minitab macro error on incompatible column types: partial writes and retry safety
0 reputation · 29 Aug 2021, 07:15 UTC
0 reputation · 29 Aug 2021, 07:15 UTC
Minitab worksheets store columns with types such as numeric, text, or date/time. Operations that combine worksheets, such as APPEND or STACK, generally require compatible column counts and types; a mismatch is a documented failure condition. Commands can be run from the command line, stored in macros, or recorded in the History folder.
When a macro runs sequentially and a command fails, the Session window reports an error, but the macro language has no transaction or rollback semantics. Earlier commands may already have modified the worksheet or output. Re-running the macro is not automatically idempotent: repeating an append can duplicate rows, and column creation may overwrite or add columns depending on the command and options.
The exact error wording and whether later macro lines still execute are version-dependent. Any design must be checked against the Help for the installed version.
This leaves an unresolved decision for macro authors:
Validate before combining, and never let the combine operation be the first thing that touches the real worksheet. A pre-flight check on column count and type, followed by a staged copy that is discarded on failure, gives you both a clean failure signal and a retry that cannot duplicate rows. Leaving the failure to the Session window and continuing is the option that makes retries unsafe.
Minitab's macro language has no transaction or rollback semantics. Commands execute in order and their effects on the worksheet, constants, and output persist. So when a combining command hits incompatible column types, everything the macro did before that line is still applied. Two consequences matter for retry design:
Whether lines after the failing command still execute depends on the ONERROR setting in effect. That is the single detail that most changes the recommendation: if the macro does not set ONERROR itself, it inherits whatever the session has, and a CONTINUE-style default will let the macro keep going past the error.
TYPE(C1) = TYPE(C2) is safer than comparing against numeric literals, because the literal codes are internal and not a documented contract.# Illustrative structure only - confirm command names, options,
# and IF/ENDIF syntax in your installed version's Help.
ONERROR STOP
# 1. pre-flight: abort before touching data
IF TYPE(C1) <> TYPE(C2)
NOTE "Type mismatch: aborting before APPEND"
EXIT
ENDIF
# 2. stage: duplicate target worksheet to a unique temp name
# 3. combine into the temp copy
# 4. swap on success; delete the temp copy on failure
Note the gap this does not close: type codes describe storage, not intent. Date/time columns are commonly stored as numeric with a display format, so a code comparison can pass while the values are still semantically incompatible. Treat the pre-flight check as a filter for the common case, not a proof.
Minitab does not give an external caller a documented return code the way a shell script does. In practice the caller has two signals: the Session log text, and a sentinel the macro writes itself — a NOTE line, a constant, or a small output file — placed only after the combine step succeeds. A sentinel is more robust than parsing error wording, because the exact wording is version-dependent. Also remember that rolling back the worksheet does not roll back constants, global storage, or files the macro wrote; if the macro touches those, the retry plan needs to cover them too.
If the macro still writes partially, the missing detail to check is whether ONERROR is set inside the macro or inherited from the session — that determines whether lines after the failing command ran at all.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.