Advanced tables and statistics > Row and table manipulation > Row manipulation > Expressions on M statements
 
Expressions on M statements
Expressions on m statements are made up of operands connected by operators. Valid operators are:
Operator
Description
+
addition
-
subtraction
*
multiplication
/
division
min()
minimum value
max()
maximum value
sqrt()
square root
exp()
exponentiation
Operators
min(ex1,ex2, ... )
This returns the lowest value of the expressions within the parentheses. Here, an expression is a number, a reference to another row in the table, or any of min(), max(), sqrt() or exp() themselves. For example, if Row1 and Row2 are the names by which those rows are identified, the expression:
ex=min(Row1,Row2)
will compare the values in rows 1 and 2 for each column separately and print whichever is the smaller in the corresponding column in the manipulated row. Suppose you have:
Row 1   10  15   9  10
Row 2    6  20   9   1
then the new row reads:
Row 3    6  15   9   1
max(ex1,ex2, ... )
max() returns the highest value of a list of expressions. In all other respects it is the same as min() above. If you write:
max(Row1,Row6)
you will see whatever is the larger value in each column of rows 1 and 6.
sqrt(expression)
This function returns the square root of the given expression. All rules listed for min() also apply to sqrt(). If the value in column 5 of row 3 is 27 and the value in column 5 of row 1 is 16, the expression:
sqrt(min(Row3,Row1))
will yield the value 4. This is the square root of 16 which is the smaller of the values in the two rows.
exp(ex1,n)
This expression only has two items in the parentheses: the first is an arithmetic expression and the second is a whole number which is the power to which ‘ex1’ is raised, that is, ex1n. For example:
exp(Row6,4)
raises the values in row 6 to the power of 4. If the value in this row is 15, the expression would be 154 which is 50625.
Operands
Operands can be:
A positive or negative integer or real number. For example:
ex=10+4–2
to create a row in which all cells contain the number 12.
A vector. That is a list of positive or negative numbers, separated by commas and enclosed in braces, where the number of values matches the number of numeric elements in the column axis.
If the breakdown axis has five columns and you want to put a new value into each cell, write:
mVector Row;ex={10.0,6.2,–8.3,15.6,–3.5}
A numeric element of the current axis which can be referenced in any of four ways described below.
Referencing numeric elements
Any of these four options is correct; just use the one which suits you best at the time. You can mix the various types in one statement if you want.
Text
Text, or as many characters of that text as make the element unique. All text must be entered exactly as it appears on the element itself, and must be enclosed in single quotes. For example, the axis region has six elements:
l region
col 117;Base;Central London;Outer London;
+England excl. London;Scotland;Wales
In one particular table it is cross-tabulated with sex, as shown here:
 
Total
Male
Female
Base
1000
470
530
Central London
166
70
96
Outer London
241
116
125
England excl. London
248
112
136
Scotland
196
92
104
Wales
149
80
69
and you want to create a row showing the total number of people living in England including London. Since this is a simple axis, you could use an n01 with the filter c=c117’1/3’, but if you were to use row manipulation instead you would write:
mEngland incl. London;ex='Central'+'Outer'+'England'
The example use only used the first word of each row text since these are all unique; in fact, just the first letter of each text would be sufficient because they are also unique. Notice also, that the words are entered exactly as they appear in the table and in the original axis specification. If this was not so, the rows would not be recognized. The table shows the result of the manipulation:
 
Total
Male
Female
Base
1000
470
530
Central London
166
70
96
Outer London
241
116
125
England excl. London
248
112
136
England incl. London
655
298
357
Scotland
196
92
104
Wales
149
80
69
Identifiers
Rows to be manipulated can be assigned identifiers using the option id= on the n, col or val statement. When these rows are named on an m statement all you have to do is use their element ID. An ID can be up to six letters or numbers long, must start with a letter and must be unique within the axis in which it occurs (r1 in ax01 is not the same as r1 in ax02). In order to be recognized on a manipulation statement, the row ID must be entered in exactly the same way as it appears on the row-creating statement. R1 on an n01 is not the same as r1 on an m statement.
Using the previous example again, this time, write:
l region
col 117;Base;Central London;%id=R1;Outer London;%id=R2;
+England excl. London;%id=R3
mEngland incl. London;ex=R1+R2+R3
col 117;Scotland='4';Wales='5'
The base row and the last two rows are not included in any manipulation so there is no need to give them IDs. The table produced by this axis is the same as that shown above.
Overall position
A third way of referring to a row is by its overall position in the axis. This is calculated by starting with the first element in the axis and counting down until the row in question is reached — all n statements, including n03 and n09, all elements on col and val statements and all intermediate m statements count as one element each. The only exceptions are n00 which is ignored and n25 which creates three unprinted rows. For information about manipulating n25 elements, see Manipulating the components of an n25.
When overall row positions are written on the m statement, they must be preceded by a hash/pound sign (#). So, if you rewrite the axis region once again you have:
l region
col 117;Base;Central London;Outer London;England excl. London
England incl. London;ex=#2+#3+#4
col 117;Scotland='4';Wales='5'
Relative position
The fourth method of picking up rows for manipulation is to use their relative position in the axis. This is obtained by counting backwards from the m statement to the row to be manipulated. All relative positions must be preceded by the ‘at’ sign (@). @0 and @ both refer to the current line; that is, they refer to the m statement itself.
Therefore, you could create the sum of people living in England including London by writing:
mEngland incl. London;ex=@3+@2+@1
where @3 is ‘Central London’ because it is three rows before the m statement, @2 is ‘Outer London’ which is two rows before the m statement and @1 is the rest of England and is the row immediately before the manipulation row.
See also
Row manipulation