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.