AGGREGATE OUTFILE={*,'file-name',file_handle} [MODE={REPLACE, ADDVARIABLES}] /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 or portable file by file name or file handle (see File Handles), or a dataset by its name (see Datasets). The aggregated cases are written to this file. If ‘*’ is specified, then the aggregated cases replace the active dataset's data. Use of OUTFILE to write a portable file is a PSPP extension.
If OUTFILE=‘*’ is given, then the subcommand MODE may also be specified. The mode subcommand has two possible values: ADDVARIABLES or REPLACE. In REPLACE mode, the entire active dataset is replaced by a new dataset which contains just the break variables and the destination varibles. In this mode, the new file will contain as many cases as there are unique combinations of the break variables. In ADDVARIABLES mode, the destination variables will be appended to the existing active dataset. Cases which have identical combinations of values in their break variables, will receive identical values for the destination variables. The number of cases in the active dataset will remain unchanged. Note that if ADDVARIABLES is specified, then the data must be sorted on the break variables.
By default, the active dataset will be sorted based on the break variables before aggregation takes place. If the active dataset is already sorted or otherwise grouped in terms of the break variables, specify PRESORTED to save time. PRESORTED is assumed if MODE=ADDVARIABLES is used.
Specify DOCUMENT to copy the documents from the active dataset into the aggregate file (see DOCUMENT). Otherwise, the aggregate file will not contain any documents, even if the aggregate file replaces the active dataset.
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 dataset 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, MEDIAN, SD, and SUM aggregation functions may only be applied to numeric variables. All the rest may be applied to numeric and 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).