= SPSS Aggregate Functions = The [[SPSS/Aggregate|AGGREGATE]] command creates variables using a mini-programming language that is largely characterized by the below functions. <> ---- == General Syntax == The number of target variables must match the number of source variables. Generally, missing values are ignored. [[SPSS/DataTypes#Strings|Strings]] will never be considered missing. Generally, a missing value are only returned if ''all'' values are missing. The exception is `SD`, which requires two non-missing values. PSPP extends this syntax with handling for user missing values. To include this type of missing values on any aggregate function, append the function name with a period. For example, `SUM.`. ---- == Variable Metadata == Only the `MAX`, `MIN`, `FIRST`, and `LAST` functions copy the metadata of a source variable. All other created variables lack labels and have a format pre-determined by the function. * `F5.3` for functions `FGT`, `FIN`, `FLT`, and `FOUT` * `F5.1` for functions `PGT`, `PIN`, `PLT`, and `POUT` * `F7.0` for functions `NU` and `NUMISS` * `F8.2` for functions `CGT`, `CIN`, `CLT`, `COUT`, `MEAN`, `MEDIAN`, `SD`, `SUM`, `N`, and `NMISS` * If weighting is not enabled, `N` and `NMISS` create variables with a format of `F7.0`. In other words, `N` and `NMISS` match the behavior of `NU` and `NUMISS` when weighting is disabled. To specify a variable label for a new target variable, list the label in quotes following the new variable name. Value labels cannot be specified. Variable formats cannot be specified. ---- == Functions == === Count functions === The '''`CGT`''' and '''`CLT`''' functions returns a count of cases with a value greater/less than a second argument. The '''`CIN`''' function returns a count of cases within an inclusive range defined by the second and third arguments. If the second argument is greater than the third, they are automatically reversed. If they are equal, `CIN` operates as an equality. The '''`COUT`''' function is the complement of `CIN`. Note: These are all unsupported in SPSS version 21 or earlier, and in PSPP version 1.6.2 or earlier. === First === The '''`FIRST`''' function returns the first non-missing value for each source variable. String values will never be considered missing. === Fraction functions === The '''`FGT`''' and '''`FLT`''' functions returns a fraction of cases with a value greater/less than a second argument. The '''`FIN`''' function returns a fraction of cases within an inclusive range defined by the second and third arguments. If the second argument is greater than the third, they are automatically reversed. If they are equal, `FIN` operates as an equality. The '''`FOUT`''' function is the complement of `FIN`. === Last === The '''`LAST`''' function returns the lastnon-missing value for each source variable. String values will never be considered missing. === Max === The '''`MAX`''' function returns a maximum non-missing value for each source variable. String values are evaluated according to codepoints. For example, `"Z"` has a higher codepoint than `"A"`, so between the two values the maximum value is `"Z"`. String values will never be considered missing. === Mean === The '''`MEAN`''' function returns a mean across cases for each source variable. Note: only valid for numeric variables. === Median === The '''`MEDIAN`''' function returns a median value for each source variable. Note: only valid for numeric variables. === Min === The '''`MIN`''' function returns a minimum non-missing value for each source variable. String values are evaluated according to codepoints. For example, `"A"` has a lower codepoint than `"Z"`, so between the two values the minimum value is `"A"`. String values will never be considered missing. === N === The '''`N`''' function returns a weighted number of cases in a break group. If specified with a variable list argument, the `N` function returns a weighted number of cases with non-missing values for each source variable. String values will never be considered missing. === Nmiss === The '''`NMISS`''' function returns a weighted number of cases with missing values for each source variable. String values will never be considered missing. === Nu === The '''`NU`''' function returns an unweighted number of cases in a break group. If specified with a variable list argument, the `NU` function returns an unweighted number of cases with non-missing values for each source variable. String values will never be considered missing. === Numiss === The '''`NUMISS`''' function returns an unweighted number of cases with missing values for each source variable. String values will never be considered missing. === Percentage functions === The '''`PGT`''' and '''`PLT`''' functions returns a percentage of cases with a value greater/less than a second argument. The '''`PIN`''' function returns a percentage of cases with a value within some range for each source variable. If the second argument is greater than the third, they are automatically reversed. If they are equal, `PIN` operates as an equality. The '''`POUT`''' function is the complement of `PIN`. === SD === The '''`SD`''' function returns a standard deviation across cases for each source variable. Note: only valid for numeric variables. === Sum === The '''`SUM`''' function returns a sum across cases for each source variable. Note: only valid for numeric variables. ---- CategoryRicottone