Tables and axes > More about axes > val statement > Testing ranges
 
Testing ranges
Quick reference
To define elements whose condition is that a variable contains a value within a given range, type:
val variable; i ;min1max1[element_txt1];min2max2[element_txt2] ...
if the maximum value in the range is to be included in that range, or:
val variable; r ;min1max1[element_txt1];min2max2[element_txt2] ...
if it is not.
If the elements contain text as well as ranges, the range can appear anywhere in the text.
Ranges which are not part of the element text can be entered after the text and separated from it by an = sign.
The base, hd=, tx= and =rej options described for col statements are also valid on val statements of this type.
More information
Val can test whether the value of any variable (data, integer or real) is within a given range. The format is almost identical to that for testing equalities, except that the equals sign is replaced by I or i for inclusive ranges (the maximum value is part of the range) or R or r for exclusive ranges (the maximum is not part of the range):
val variable;[Base];[hd=text];I|i|R|r;[tx=text[;range1 [text1];range2 [text2]; ...
Ranges are entered as the minimum and maximum values separated by a hyphen (min-max) or slash (min/max). If no upper value is given, a maximum of infinity is assumed. Thus you might have:
val c(110,111);Base;hd=Size of Household;I;1-2 People;
+3-4 People;5-6 People;7 or More People
If the value in c(110,111) is in the range 1-2, the respondent is in the element entitled ‘1‑2 People’; if the value in c(110,111) is 10, they are in the element ‘7 or More People’. All ranges are inclusive because the example uses the i operator.
The r operator can be used to indicate that the maximum value specified is not part of the range. You might have:
val liters;Base;hd=Liters Bought Per Person;R;0-10.5 Liters;
+10.5-20.0 Liters;20.0-35.5 Liters;35.5 or More Liters
In this situation, the first element contains the number of households in which the number of liters bought was between 0 and 10.4999 per person; the second contains the number of households in which the number of liters purchased per person was between 10.5 and 19.9999, and so on. The last element includes all households in which the number of liters per person is 35.5 or more.
Where the numbers defining the ranges are not part of the element texts, the text can be entered followed by an equals sign and the range specification, as described in the previous section.
Note When defining ranges in element texts, an actual range must be specified, for example, 10-20 or 25-50. It is not enough to say, under 25, for example as this is interpreted as 25-99.
If both numbers in a range are negative, the smaller value (that is, the one farthest away from zero) must come first. For example:
val c(1,5);i;-10--5;-4-0;1-10
See also
val statement