arraymultisort
OLDARRAY
,
NEWARRAY
,
ROWSEP
,
COLSEP
,
SORTSPECS

The arraymultisort statement sorts a two-dimensional array on the key of one or more of its columns.


Parameters

This statement has five parameters:

oldarray – The original array.

newarray – The sorted array.

rowsep – The separator between rows of the array.

colsep – The separator between column elements in each row of the array.

sortspecs – A semicolon-delimited text array containing the specifications for the sort. Each element of this array must specify a column number (counting from the left) and the nature of the sort. The letter ‘n’ specifies a true numeric sort, ‘r’ specifies a pseudo-numeric(or right-justified) sort and the absence of both of these specifies a conventional sort up. The letter, ‘d’, specifies a sort down.

Numeric sorts only work with positive integers (1, 22, 450, etc.) This option will not work correctly if there are extra characters in the numbers, for example ‘$’, decimal points or commas. If the data contains non-integer numbers you may be able to use the ‘r’ option if all of the data is consistently formatted. However this statement cannot sort negative values correctly, whether they are integers or contain additional characters or not.

Any combination of numbers and letters is valid but the presence of both n and r will result in a numeric sort. Letters may be upper or lower case and the order of letters and numbers is unimportant. Extraneous non-numeric characters are ignored and ‘n’ takes precedence over ‘r’ if both are present, regardless of the order in which they are encountered. The order of the sort specifications is important as it determines the order in which successive sorts are conducted. If multiple sort specifications are provided, they will be evaluated in turn, from right to left (primary;secondary;tertiary;…).

The numeric component of this statement differs from the ArrayNumericSort statement in one important respect. The output from ArrayNumericSort has leading zeros stripped from all array elements, whether alpha or numeric. The ArrayMultiSort statement, when used in numeric mode, sorts on this same basis but assumes that the user does not wish the contents of the array to be edited, but only to be rearranged according to a sort specification. Hence, the array elements will be sorted into the same order as is done by ArrayNumericSort but any leading zeros will be retained.

An empty or single-element input array is returned unchanged.


Description

This statement sorts a two-dimensional array on the key of one or more of its columns. Consider a two-dimensional array, InArray, with RowSep = ¶ (carriage return) and ColSep = “;”

red;3;A
blue;5;A
red;5;B
blue;3;B

The statement,

ArrayMultiSort InArray,OutArray,RowSep,ColSep,"1d"

will produce:

red;3;A
red;5;B
blue;5;A
blue;3;B

The statement,

ArrayMultiSort InArray,OutArray,RowSep,ColSep,"2n;1d"

will produce:

red;3;A
red;5;B
blue;3;B
blue;5;A

In each individual sort, rows with equal elements in the key column retain their order. In the ‘2n’ sort, the numbers are sorted and then the ‘1d’ sort retains that order for equal values in the first column.

Because extraneous non-numeric characters are ignored and ‘n’ takes precedence over ‘r’, a sort specification of “Dragons3” will be interpreted as 3nd, resulting in a numeric sort down on column 3. Similarly, “2Hello Jim” will sort up on column 2.


See Also


History

VersionStatusNotes
10.0No ChangeCarried over from Panorama 6.0.