Tables and axes > More about axes > Percentage differences
 
Percentage differences
Quick reference
To calculate the difference between two percentages, type:
keep[=pc_type]
on one of the elements to be used in the calculation. The default is to use unrounded figures in the calculation; to use rounded figures, enter pc_type as print.
Then identify the second percentage with either:
op=A
to subtract the keep= percentage from this element, or:
op=B
to subtract the percentage for this element from the keep= percentage.
More information
Quantum can calculate the difference between two percentages. The difference is the result of subtracting one percentage value from the other; for example, 25%-15%=10%. There are three options:
keep[=pctype]
Marks the element or table defining the type of percentage to be used in the difference calculation (that is, row, column, total, and so on). pctype is a keyword which defines whether the calculation should use the unrounded percentages which Quantum stores internally, or the rounded ones which are printed in the table. The default is keep=value which uses the unrounded figures; use keep=print to use the rounded ones.
op=B
Subtract the percentage for this element or table from the keep percentage.
op=A
Subtract the keep percentage from the percentage for this element or table.
Examples
For example, the axis segment:
n11Base
n01Brand A: January;c=c115'1';keep;op=12
n01Brand A: February;c=c115'2';op=12
n01Increase(+) / Decrease(-) Jan to Feb;c=c115'2';op=A
calculates the difference between the percentages for January and February by subtracting the January percentage from the current percentage.
For example:
 
Base
Brand A: January
100
 
  50%
Brand A: February
150
 
  75%
Increase(+) / Decrease(-)
  25%
Jan to Feb
 
This example creates a separate element for the percentage difference. If you prefer, you can create an axis in which all elements except the first one contain percentage differences. If you rewrite the example as:
n11Base
n10Brand A: January;c=c115';keep;op=12
n10Increase/Decrease to February;c=c115'2';op=A
the table becomes:
 
Base
Brand A: January
100
 
  50%
Increase/Decrease to
  25%
February
 
To see the actual figures for February as well, write the op=A element as:
n01Increase/Decrease to February;c=c115'2';op=12A
This statement produces this table:
 
Base
Brand A: January
100
 
  50%
Increase/Decrease to
150
February
  75%
 
  25%
Order of options
The order of options with op= is important: when Quantum encounters a keep element, it looks at the options for that element (or the defaults for that table or run if none are defined) and keeps the ‘last’ one. In this instance, ‘last’ means last in the order:
1
Absolutes
2
Column % on current base
6
Column % on first base
0
Row percentage
&
Total percentage
8
Indices
3
Row ranks
So with op=120, keep stores the row percentage for calculation purposes. In the examples above, the options were always op=12, so all calculations were based on column percentages.
If a cell in the op=A/B element does not have the percentages required by the keep element, it will use whatever figures are available in the op=A/B element, even if these happen to be absolute figures rather than percentages. This might happen if the op=A/B element has a row percentage flag (for example, op=10A), but the table or run does not have the option acr100 for percentages on the base column.
Where a table contains keep and op=A/B options in more than one axis, the keep/op= in the column axis overrides that in the row axis, which in turn overrides that in the third dimension axis. Keep/op= in higher dimensions are ignored.
Keep and op=A/B can not appear on the same element. Therefore, if you want a table of rolling differences (that is, the difference between the current element and the previous element), you need to create a separate element for each percentage difference element, which might or might not be printed in the table. Here are two variations of such an axis:
n01January;c=c115'1'
n01February;c=c115'2';keep
n01% change Jan to Feb;c=c115'1';op=B
n01March;c=c115'3';keep
n01% change Feb to Mar;c=c115'2';op=B
n01April;c=c115'4';keep
n01%change Mar to Apr;c=c115'3';op=B
In this example, the % change element refers to the previous rather than the current month, so that the difference is always calculated by subtracting the current month from the previous month.
This might produce the table:
January                        
25%
February
28%
% change Jan to Feb
3%
March
26%
% change Feb to Mar
-2%
April
22%
% change Mar to Apr
-4%
To create the same table so that only percentage difference elements are shown for each month, the axis can be written with suppressed elements, thus:
n01January;c=c115'1';keep;op=2
n01Change January to February;c=c115'2';op=2A
n15;c=c115'2';keep;op=2
n01Change February to March;c=c115'3';op=2A
n15;c=c115'3';keep;op=2
n01Change March to April;c=c115'4';op=2A
The table produced is as follows:
January                         
25%
Change January to February
3%
Change February to March
-2%
Change March to April
-4%
Note n15 statements only work with keep when the axis is used for the rows of a table.
The examples so far have all referred to elements in axes, but keep and op=A/B are also valid on tab statements to generate tables in which the cell values are the differences between corresponding cells in two tables. Generally, you use this facility when the two tables refer to different sections of the population. For example:
tab prefer region;keep
tab prefer region;c=c123'4';op=B
The first table is the whole population and the second table is, say, everyone who works full-time. Quantum does not print this second table as such. Instead, it creates it in memory but then subtracts the figures for that table from those in the kept table and prints the results as the second table. Thus, if the population base for the eastern region is 17% and the base of full-time workers for the same region is 10%, the figure in the final table will be 7%.
Note Percentage signs are printed according to the requirements for the table as a whole.
op=A and op=B are mutually exclusive; they cannot be present together.
See also
More about axes