Data editing > Expressions > Arithmetic expressions
 
Arithmetic expressions
The simplest form of arithmetic expression is a single positive or negative number such as 10 or ‑26.5 or an integer or real variable.
Although the C array is data, columns may also be used in arithmetic when the response coded into those columns is a numeric response, such as a respondent’s age or the number of different shops they visited. For example, if columns 243 to 247 contain the codes 4,7,2,6 and 0 respectively the value in c(243,247) could be read as 47,260. Similarly, if columns 45 to 48 contain 7, 8, a dot and 2 respectively, the value in cx(45,48) would be 78.2.
Blank columns in a field are ignored when the codes in those columns are evaluated. Thus, if columns 20 to 21 contain the codes 6 and 7 respectively, and column 22 is blank, the codes in c(20,22) will be evaluated as 67. A similar result is produced if the blank column appears anywhere else in the field. All the examples of c(20,22) below produce an arithmetic value of 67:
+----2----+ +----2----+ +----2----+
     67 67 6 7
The same applies to multicoded columns. If you use a multicoded column as part of an arithmetic expression, the multicoded column will be ignored. The exception to this is a multicode of a digit and a minus sign which creates a negative number: a minus sign anywhere in a numeric field negates the value in the field as a whole, not just the number it is multicoded with. For example:
----+----1----+----2
5 3778 is 5378
9
0
 
2---+----3----+----4
12-4 is -1234
3
 
4---+----5----+----6
83- is -83
See
Combining arithmetic expressions
Counting the number of codes in a column
Generating a random number
See also
Expressions