Language Reference |
returns the locations of the unique by-group combinations for a sorted or indexed matrix
The UNIQUEBY function returns a column vector, whose th row gives the row in index whose value is the row in matrix of the th unique combination of values in the by columns. Suppose you submit the following statement:
unique_rows = uniqueby( matrix, by, index);
Once you have submitted this statement, the following statement gives the values of the unique by combinations:
unique = matrix[ index[ unique_rows ], by ];
In addition, the following statement gives the number of unique values:
n = nrow( unique );
The following statement gives the number of rows in the th by combination, except for the last combination.
size = unique_rows[i+1] - unique_rows[i];
The last combination is given by the following statement:
size_last = nrow(matrix) - unique_rows[nrow(unique_rows)] + 1;
If matrix is already sorted according to the by columns (see the SORT call), then UNIQUEBY can be called with 1:nrow(matrix) for the index argument, as follows:
unique_loc = uniqueby( matrix, by, 1:nrow(matrix) );
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.