Aggregate functions
AVG(<expression>)
Returns the average of the values defined in the expression. This function can be used with numeric data only.
BASE(<expression>)
Returns the total number of cases included in the expression. Generally, the base includes every case for which the value is not NULL.
COUNT(<expression>)
Returns a count of the cases selected by the expression.
SUM(<expression>)
When used with numeric data, returns the sum of the values. When used with categorical data, it returns the union of the categorical values.
MIN(<expression>)
Returns the lowest value defined in the expression.
MAX(<expression>)
Returns the highest value defined in the expression.
STDEV(<expression>)
Returns the standard deviation of the values defined in the expression. This function can be used with numeric data only. The standard deviation is a measure of dispersion around the mean. In a normal distribution, 68% of cases fall within one standard deviation of the mean and 95% of cases fall within 2 standard deviations. For example, if the mean age is 45 with a standard deviation of 10, then 95% of the cases would be between 25 and 65 in a normal distribution.
Up-leving one level
The following top-level expression uses the up-lev syntax to up-lev the data in the Person-level Gender variable to the top level. This expression returns the number of males in the household.
Sum(Person.(Gender = {male}))
The following expression is at the Person level and includes the up-lev syntax to promote the data in the Trip-level DaysAway variable to the Person level. This expression selects women who took overseas trips that lasted a total of more than 20 days.
Gender = {Female} And Age > 16 And Sum(Trip.(DaysAway)) > 20
The following expression is at the Vehicle level and includes the up-lev syntax to promote the data in the Rating grid to the Vehicle level. It selects vehicles for which the respondent selected the Very good category in response to at least one iteration of the Vehicle-level Rating grid.
Sum(Rating.(Column * {Very_good}))
Up-leving two levels
You can use the up-lev syntax multiple times to up-lev by more than one level. For example, the following expression is at the top (HDATA) level and the data in the Trip-level DaysAway variable has been up-leved twice to the top level.
Sum(Person.(Sum(Trip.(DaysAway > 20))))
This expression selects households in which at least one person took at least one overseas trip that lasted more than 20 days. If you want to select households in which at least one person took overseas trips that altogether lasted more than 20 days, move the comparison operator outside the innermost parentheses:
Sum(Person.(Sum(Trip.(DaysAway)) > 20))
Working with parallel levels
The preceding examples use levels that have a direct parent-child relationship. However, some data sets contain levels that are not related to each other. For example, the diagram that shows the levels structure of the Household sample, also shows that the Person and Vehicle levels are parallel to each other (on different branches of the tree). This means that the data in the two levels is not directly related to each other. However, sometimes you might want to include data from parallel levels in an expression. For example, you might want to select men who live in households that have a motorbike. To do this, use the data in the Vehicle level in your Person-level expression.
When you include data from a parallel level in an expression, you must up-lev the data to the first common ancestor level and then down-lev the data to the level of the expression. In the Household sample, the only level that is an ancestor of both the Person and Vehicle levels is the top (HDATA) level. The following expression up-levs the Vehicle-level data to the top level and down-levs it to the Person level. It selects men who live in a household that has one or more motorbike.
^.Sum(Vehicle.(VehicleType = {Motorbike})) > 0 And Gender = {Male}
See also