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:
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).