Advanced tables and statistics > Row and table manipulation > Manipulating whole tables
 
Manipulating whole tables
Quick reference
To manipulate the figures in a complete table, type:
ex manip_expression
underneath the tab statement for that table.
More information
New tables can be generated by manipulating tables created previously in the current run or anywhere in any other run. For example, in a countrywide survey, the data might have been collected on a regional basis, with each region having a separate directory. You might want to create some tables which refer to the country as a whole rather than to a particular region. With table manipulation, you can create these tables separately and then add them together to create a new table for the whole country.
Table manipulation of any sort is controlled by the ex statement:
ex expression
where the expression defines the type of manipulation required.
An ex statement by itself means nothing: it must always follow a tab statement defining the basic table to be manipulated. The unmanipulated table created by the tab statement is not printed as part of the output. For example:
tab ax01 bk01
ex *2.0
creates the table ax01 by bk01, stores the cell values and then multiplies them by 2.0 before writing them in the tables file.
The expression comprises operands connected by operators. Valid operators are:
Operator
Description
+
addition
-
subtraction
*
multiplication
/
division
min()
minimum value
max()
maximum value
sqrt()
square root
exp()
exponentiation
These are the same as for row manipulation, except that the expressions enclosed in the parentheses with min(), max(), sqrt() and exp() refer to whole tables rather than rows. For a full description of these operators and other components of manipulation expressions, see Row manipulation.
Operands can be constants or vectors or they can be references to whole tables as discussed below. For example, the statements:
tab ax01 bk01
ex *1.45
generates a table by multiplying each cell in the table by 1.45, as shown here:
Original Table (not printed)
           
Base   
Col1   
Col2   
Base
70
30
40
Row1
25
10
15
Row2
32
12
20
Row3
13
8
5
Manipulated table
           
Base   
Col1   
Col2   
Base
101.5
43.5
58.0
Row1
36.3
14.5
21.8
Row2
46.4
17.4
29.0
Row3
18.8
11.6
7.2
Vectors can be used to replace numbers in the table created by the previous tab statement or to define constants by which the cells in that table are to be incremented or decremented prior to printing. When supplying raw numbers all you have to do is type in the numbers separated by commas and enclosed in braces. For example:
tab ax01 bk01
ex {80.0,32.0,48.0,26.0,11.0,15.0, ...}
This creates the table ax01 by bk01 but instead of showing the cell counts read from the data (see example above) it shows the values specified by the ex statement. Hence, the table base is 80.0 instead of 70, the base for Col1 is 32, and so on. Any cells for which values have not been given are shown as zero.
On the other hand, when vectors define incremental values any cell for which any incremental value has not been given will retain its original value. For example, you could create a table of ax01 by bk01 with a base of 80 respondents as before, except that instead of entering the exact values for each cell you enter the values by which the original totals are to be incremented:
tab ax01 bk01
ex +{10.0,2.0,8.0,1.0,1.0,0, ...}
The difference between the original base (70) and the manipulated base (80.0) is 10.0, the original base for Col1 (30) must be incremented by 2.0 to reach the required figure of 32.0, and so on.
In this example, the braces are with a plus sign, but any of the operators -, * and / are equally valid. Long vector lists can be spread over more than one line by ending the first line at a comma and preceding the vector at the start of the second line with a ++ continuation.
See
Referring to tables in the current run
Manipulating tables from other runs
Manipulating more than one table
See also
Row and table manipulation