3.3.2.56 Sort

Sort the given variables, or sort all values in the worksheet against a dataset.

Please see the wsort X-Function.

Syntax:

sort  [option] object(s)

The built-in sort( ) function can also be used to sort a dataset. For example:

book1_a = sort(book1_b);
sorts book1_b in ascending order, then assigns it to book1_a.

Options:

no option variable list; Sort the given variables in ascending order

Syntax: sort no option no option variable1 variable2 ... variable10

Sort the given variables in ascending order by value. Reassign the values such that variable1 contains the smallest value, and variable10 (or the last variable given) contains the highest value.

-c c1 c2 datasetName; Sort all columns between c1 and c2 in ascending order against datasetName

Syntax: sort -c c1 c2 datasetName

Sort all columns between c1 and c2, inclusive, in ascending order, against the specified worksheet dataset. Row integrity is maintained.

-cd c1 c2 datasetName; Sort all columns between c1 and c2 in descending order against datasetName

Syntax: sort -cd c1 c2 datasetName

Sort all columns between c1 and c2, inclusive, in descending order, against the specified worksheet dataset. Row integrity is maintained.

-w worksheetName datasetName; Sort worksheet in ascending order against specified dataset

Sort the entire worksheet in ascending order against values in the specified dataset. Row integrity is maintained.

-wd worksheetName datasetName; Sort worksheet in descending order against specified dataset

Syntax: sort -wd worksheetName datasetName

Sort the entire worksheet in descending order against values in the specified dataset. Same as -w, but sort in descending order.

Examples:

Example 1

If Book1 is the active window, the following script sorts the 2nd through the 7th columns against Book1_c, in ascending order. If Book1_c is not in the specified range, the relationship between it and the other columns is destroyed.

sort -c 2 7 Book1_c;

Example 2

The next script sorts all columns in the Book1 worksheet against the Book1_c dataset.

sort -wd Book1 Book1_c;

The following script uses the wks.nrows object property to assign the number of rows in several worksheets to several variables. The sort command is used to find the smallest value and place it in the A variable. The value of the smallest number of rows is typed to the Script window.

A = $(Book1!wks.nrows);
B = $(Book2!wks.nrows);
C = $(Book3!wks.nrows);
D = $(Book4!wks.nrows);
sort A B C D;
type "The smallest worksheet has $(A) rows.";

See Also:

Sort, Sort