Next: , Previous: Data Manipulation, Up: Data Manipulation



9.1 AGGREGATE

     AGGREGATE
             OUTFILE={*,'filename'}
             /PRESORTED
             /DOCUMENT
             /MISSING=COLUMNWISE
             /BREAK=var_list
             /dest_var['label']...=agr_func(src_vars, args...)...

AGGREGATE summarizes groups of cases into single cases. Cases are divided into groups that have the same values for one or more variables called break variables. Several functions are available for summarizing case contents.

The OUTFILE subcommand is required and must appear first. Specify a system file by file name string or file handle (see FILE HANDLE). The aggregated cases are written to this file. If * is specified, then the aggregated cases replace the active file.

By default, the active file will be sorted based on the break variables before aggregation takes place. If the active file is already sorted or otherwise grouped in terms of the break variables, specify PRESORTED to save time.

Specify DOCUMENT to copy the documents from the active file into the aggregate file (see DOCUMENT). Otherwise, the aggregate file will not contain any documents, even if the aggregate file replaces the active file.

Normally, only a single case (for SD and SD., two cases) need be non-missing in each group for the aggregate variable to be non-missing. Specifying /MISSING=COLUMNWISE inverts this behavior, so that the aggregate variable becomes missing if any aggregated value is missing.

If PRESORTED, DOCUMENT, or MISSING are specified, they must appear between OUTFILE and BREAK.

At least one break variable must be specified on BREAK, a required subcommand. The values of these variables are used to divide the active file into groups to be summarized. In addition, at least one dest_var must be specified.

One or more sets of aggregation variables must be specified. Each set comprises a list of aggregation variables, an equals sign (=), the name of an aggregation function (see the list below), and a list of source variables in parentheses. Some aggregation functions expect additional arguments following the source variable names.

Aggregation variables typically are created with no variable label, value labels, or missing values. Their default print and write formats depend on the aggregation function used, with details given in the table below. A variable label for an aggregation variable may be specified just after the variable's name in the aggregation variable list.

Each set must have exactly as many source variables as aggregation variables. Each aggregation variable receives the results of applying the specified aggregation function to the corresponding source variable. The MEAN, SD, and SUM aggregation functions may only be applied to numeric variables. All the rest may be applied to numeric and short and long string variables.

The available aggregation functions are as follows:

FGT(var_name, value)
Fraction of values greater than the specified constant. The default format is F5.3.
FIN(var_name, low, high)
Fraction of values within the specified inclusive range of constants. The default format is F5.3.
FLT(var_name, value)
Fraction of values less than the specified constant. The default format is F5.3.
FIRST(var_name)
First non-missing value in break group. The aggregation variable receives the complete dictionary information from the source variable. The sort performed by AGGREGATE (and by SORT CASES) is stable, so that the first case with particular values for the break variables before sorting will also be the first case in that break group after sorting.
FOUT(var_name, low, high)
Fraction of values strictly outside the specified range of constants. The default format is F5.3.
LAST(var_name)
Last non-missing value in break group. The aggregation variable receives the complete dictionary information from the source variable. The sort performed by AGGREGATE (and by SORT CASES) is stable, so that the last case with particular values for the break variables before sorting will also be the last case in that break group after sorting.
MAX(var_name)
Maximum value. The aggregation variable receives the complete dictionary information from the source variable.
MEAN(var_name)
Arithmetic mean. Limited to numeric values. The default format is F8.2.
MIN(var_name)
Minimum value. The aggregation variable receives the complete dictionary information from the source variable.
N(var_name)
Number of non-missing values. The default format is F7.0 if weighting is not enabled, F8.2 if it is (see WEIGHT).
N
Number of cases aggregated to form this group. The default format is F7.0 if weighting is not enabled, F8.2 if it is (see WEIGHT).
NMISS(var_name)
Number of missing values. The default format is F7.0 if weighting is not enabled, F8.2 if it is (see WEIGHT).
NU(var_name)
Number of non-missing values. Each case is considered to have a weight of 1, regardless of the current weighting variable (see WEIGHT). The default format is F7.0.
NU
Number of cases aggregated to form this group. Each case is considered to have a weight of 1, regardless of the current weighting variable. The default format is F7.0.
NUMISS(var_name)
Number of missing values. Each case is considered to have a weight of 1, regardless of the current weighting variable. The default format is F7.0.
PGT(var_name, value)
Percentage between 0 and 100 of values greater than the specified constant. The default format is F5.1.
PIN(var_name, low, high)
Percentage of values within the specified inclusive range of constants. The default format is F5.1.
PLT(var_name, value)
Percentage of values less than the specified constant. The default format is F5.1.
POUT(var_name, low, high)
Percentage of values strictly outside the specified range of constants. The default format is F5.1.
SD(var_name)
Standard deviation of the mean. Limited to numeric values. The default format is F8.2.
SUM(var_name)
Sum. Limited to numeric values. The default format is F8.2.

Aggregation functions compare string values in terms of internal character codes. On most modern computers, this is a form of ASCII.

The aggregation functions listed above exclude all user-missing values from calculations. To include user-missing values, insert a period (.) at the end of the function name. (e.g. SUM.). (Be aware that specifying such a function as the last token on a line will cause the period to be interpreted as the end of the command.)

AGGREGATE both ignores and cancels the current SPLIT FILE settings (see SPLIT FILE).