cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Learn how to build custom Python data connectors and further customize JMP’s Data Connector Framework with the Python Data Connector Demo, available now in the JMP Marketplace!
  • See how to move from signal modeling to system modeling at the first JMP Aerospace Analytics webinar. Register. June 18, 1 p.m. US Eastern Time.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
BabyDoragon
Level II

In a situation where both numbers and text are present, how can we achieve the correct sorting?

As shown in the following JSL, sorting works correctly in ascending order when only numbers are present; however, when mixed with text, converting to numbers before sorting causes issues. What methods can be used to solve this problem?

stepList = {"2", "3", "10", "9", "1"};
stepListSort = Sort List( stepList );
stepListNum = {};
For( i = 1, i <= N Items( stepList ), i++, 
	Insert Into( stepListNum, Num( stepList[i] ) )
);
stepListNumSort = Sort List( stepListNum );

stepListWithString = {"2", "3", "10_New", "9", "1"};
stepListWithStringSort = Sort List( stepListWithString );
Show( stepListWithSting );
stepListNum = {};
For( i = 1, i <= N Items( stepList ), i++, 
	Insert Into( stepListNum, Num( stepListWithString[i] ) )
);
stepListWithStringNumSort = Sort List( stepListNum );
1 REPLY 1
jthi
Super User

Re: In a situation where both numbers and text are present, how can we achieve the correct sorting?

JMP uses different ways of sorting in different places (there is at least one old post of mine asking about this but might be difficult to find). You can try going through data table

Names Default To Here(1);

stepListWithString = {"2", "3", "10_New", "9", "1"};

dt = New Table("A",
	New Column("A", Character, Nominal, Values(stepListWithString))
);
dt << Sort(By(:A), Replace Table, Order(Ascending));
stepListWithStringSort = dt[0, 1];
Close(dt, no save);

show(stepListWithStringSort);
// stepListWithStringSort = {"1", "2", "3", "9", "10_New"};
-Jarmo

Recommended Articles