SUM Function
Generates the sums of the numeric elements at the lowest levels of a dynamic array and returns a new dynamic array in which each element at the next level is replaced by the sum of its contents.
Syntax
SUM(dynArray)
Syntax Elements
dynArray An expression that evaluates to a dynamic array.
Operation
-
If dynArray contains subvalues, each value that contains subvalues is replaced by the sum of those subvalues. Non-numeric subvalues are discarded and null subvalues evaluate to zero.
Note
If an attribute contains no values, only subvalues, SUM replaces the attribute with the sum of those subvalues.
-
If dynArray contains no subvalues, the same process is carried out on the values, replacing attributes with the sums of their values.
-
If dynArray contains no values, the same process is carried out on the attributes, replacing the complete array with the sum of its attributes.
Note
This behaviour can be changed with the SUM.NULL compatibility option.
See Also
Examples
-
If dynArray contains the following:
2\4\6]3^18]9\7
the SUM function returns:
12]3^18]16
The subvalues in the first value of attribute 1 have been replaced by the number 12 (2 + 4 + 6). Similarly, the subvalues in the second value of attribute 2 have been replaced by the number 16 (9 + 7).
-
If dynamic array D contains 4]1]6^4^6]1, the statement
C = SUM(D)
sets the variable C to 11^4^7, where 11 is the sum of the initial value list of 4]1]6 and 7 is the sum of the trailing value list of 6]1.
-
If dynamic array AGES contains 22^34^25^57^54, the statement
A = SUM(AGES)
assigns the value 192 (the sum of all the ages) to variable A.
-
If dynamic array A contains 1\2\\A]4]B\C]D\E\^5^6\3^2]1\1]3^5]F, the following program:
B = SUM(A) C = SUM(B) D = SUM(C) Z = SUMMATION(A) CRT "A:",A CRT "B:",B CRT "C:",C CRT "D:",D CRT "Z:",Z END
displays the following:
A: 1\2\\A]4]B\C]D\E\^5^6\3^2]1\1]3^5]F
B: 3]4]]0^5^9^2]2]3^5]F
C: 7^5^9^7^5
D: 33
Z: 33