Publication date: 07/08/2024

Sort a Data Table

The Sort() message rearranges the rows of a table according to the values of one or more columns, either replacing the current table or creating a new table with the results. Specify ascending or descending sort for each By column.

dt << Sort(("<Private>"|"<Invisible>"), <Replace Table>, By(columns), Order(Descending | Ascending), <Output Table Name(name))>

The following example creates a new data table based on Big Class.jmp that sorts the data in descending order by age and by name:

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
sortedDt = dt << Sort(
	By( :age, :name ),
	Order( Descending, Ascending ),
	Output Table Name( "Sorted age name" ) );

You can also use an associative array to sort values in a column. The associative array gives you a quick look at unique values in a column. See Sort a Column’s Values in Lexicographic Order.

Want more information? Have questions? Get answers in the JMP User Community (community.jmp.com).