Tables and axes > More about axes > val statement > Testing for arithmetic equality
 
Testing for arithmetic equality
Quick reference
To define elements whose condition is that a variable contains a specific value, type:
val variable; = ;number1 [element_txt1];number2 [element_txt2] ...
If the elements contain text as well as a number, the number can appear anywhere in the text.
If the value is not part of the text, type:
val variable; = ;element_text = number; ...
The base, hd=, tx= and =rej options described for col statements are also valid on val statements of this type.
Syntax
val variable;[Base];[hd=Text];=;[tx=Text];n1 [Text1]; ... ;nn [Textn]
variable
The data, integer or real variable whose value is to be tested.
n1 to nn
The values against which the variable is to be compared.
Text1 to Textn
The row descriptions to be printed in the table.
More information
Val can be used to test whether the value of a variable is equal to a given value. If it is equal, the cell count is incremented by 1. The format is:
The equals sign indicates that the test is for arithmetic equality rather than ranges. Base, hd= and tx= are optional and create the base, sub-heading and text-only rows of the table as described for col statements.
For example, suppose c(110,111) contains data on the number of people in the household, and you want to set up a table showing how many respondents live in households containing 1, 2, 3, 4, 5 or 6 people, so you write:
val c(110,111);Base;Hd=Number in Household;=;1 Person;2 People;
+3 People;4 People;5 People;6 People
If the arithmetic value of c(110,111) is equal to 1, the respondent is included in the second row of the table (the first row is the base row). If the value is equal to 6, the respondent falls into the row reading ‘6 People’.
The text is printed exactly as it appears between the semicolons. The expression ‘One person’ is not valid because the program can’t read ‘One’. Each text has to have a number in it or associated with it so that Quantum knows what to check for. Texts can contain any characters you like except semicolons and other numbers. It can also come on both sides of the number: the parameter ‘For 5 people’ is valid.
Now look at the table itself:
                                       Absolutes/Row Percentages
Base: All Who Bought Fabric Conditioner
                          Brand Bought Most Often
                 Base   Brand A   Brand B   Brand C    Others
                 --------------------------------------------
Base              190      54        50        55         31
                100.0%   23.4%     26.3%     28.9%      16.3%
Number in Household
1 Person           32      12        11         2          7
                100.0%   37.5%     34.4%      6.3%      21.9%
2 People           82      16        14        42         10
                100.0%   19.5%     17.1%     51.2%      12.2%
3 People           18       6         6         2          4
                100.0%   33.3%     33.3%     11.2%      22.2%
4 People           19       6         6         5          2
                100.0%   33.3      33.3%     26.3%      11.1%
5 People            9       3         1         4          1
                100.0%   33.3%     11.1%     44.4%      11.1%
6 People            7       2         3         0          2
                100.0%   28.6%     42.9%        0%      28.6%
Others             23       9         9         0          5
                100.0%   39.1%     39.1%        0%      21.7%
The last row is entitled ‘Others’: it gathers together all respondents living in households of more than six people. This was created by Others=rej at the end of the val statement and collects all respondents not included in any of the previous elements. You could equally well have written an n01 statement with the condition c=–6 or just c=– to collect anyone not included in the previous six elements.
Sometimes, as is the case with Other, the numbers are not a valid part of the element text. Suppose c(132,133) contains codes for the brand of fabric conditioner bought most often. If c(132,133)=$77$, the brand purchased most often was Brand A, and so on. To set up the table shown above, use an equals sign between the Brand and the number which represents it:
val c(132,133);Base;hd=Brand Bought Most Often;=;Brand A=77;
+Brand B=79;Brand C=81;Others=rej
If the values on the val statement are just numbers which are incremented by 1 for each element, they can be abbreviated using the notation:
val c(m,n);Base;=;start:end
start is the value required for the first element and end is the value required for the last element. If there are spaces between the start and end values and the colon, the range will not be recognized.
When the axis is used, Quantum creates as many elements as there are numbers in the range. For example:
val c(110,111);Base;hd=Number of people in household;=;1:9
creates ten elements: one for the base and nine for the numbers in the range 1:9.
When elements are defined in this way, no element texts can be entered since Quantum will use the individual numbers in the range as the row and column texts.
Usually the values for each element are positive, but val can also cope with negative numbers. If the data contains three records:
-10
-0010
10
the val statement:
val c(1,5);=;-10;0;10
reports that there are two records with the value –10, and one with the value 10.
See also
val statement