cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
markschahl
Level V

Scripting Table Sort by User Defined Column

Warning - scripting newbie @ work. I'm working on a script, a part of which sorts the data table by the user selected column (obtained by ColList selection and Eval List).

 

This does not work, it brings up the Sort dialog, which I don't want:

 

 

dt << Sort( By(_userCol), Order(Ascending), Replace Table);

 

When I hover over _userCol, the assigned column is shown in the scripting window.  If I use the exact column name, it works without bringing up the Sort dialog:

 

 

dt << Sort( By(:Timestamp), Order(Ascending), Replace Table);

 

How can I script this using the variable _userCol?

 

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
pmroz
Super User

Re: Scripting Table Sort by User Defined Column

You need to use the column function or the eval function:

 

 

dt = open("$sample_data\Big Class.jmp");
 
_userCol = "age";
 
dt << Sort( By(column(dt, _userCol)), Order(Ascending), Replace Table);

 

 

OR

 

 

dt << Sort( By(eval(_userCol)), Order(Ascending), Replace Table);

 

View solution in original post

5 REPLIES 5
pmroz
Super User

Re: Scripting Table Sort by User Defined Column

You need to use the column function or the eval function:

 

 

dt = open("$sample_data\Big Class.jmp");
 
_userCol = "age";
 
dt << Sort( By(column(dt, _userCol)), Order(Ascending), Replace Table);

 

 

OR

 

 

dt << Sort( By(eval(_userCol)), Order(Ascending), Replace Table);

 

markschahl
Level V

Re: Scripting Table Sort by User Defined Column

Thanks. Solved my problem. Subsequently learned about using As Column(_usercol) when using the column in a formula.

Re: Scripting Table Sort by User Defined Column

Hello Sir,

Is it possible if i can order the the table by a predefined list instead of ascending or descending order. e.g

dt = open("$sample_data\Big Class.jmp");
 _userCol = "name";
 dt << Sort( By(column(dt, _userCol)), Order(Descending), Replace Table);

instead of the above, i like to order the table by name in a order given by "list" below? list={"BARBARA","ALFRED","CHRIS","ALICE","AMY","CAROL","CLAY","DANNY","DAVID","EDWARD","ELIZABETH","FREDERICK","HENRY","JACLYN","JAMES","JANE","JEFFREY","JOE","JOHN","JUDY","KATIE","KIRK","LAWRENCE","LESLIE","LEWIS","LILLIE","LINDA","LOUISE","MARION","MARK","MARTHA","MARY","MICHAEL","PATTY","PHILLIP","ROBERT","SUSAN","TIM","WILLIAM"};
txnelson
Super User

Re: Scripting Table Sort by User Defined Column

Well....kind of.

If you set the "Value Ordering" column property for the column you want oredered, and then sort by that column, the resulting sort will be ordered based upong the specified order.

 

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/big class.jmp" );

dt:name << set property(
	"value ordering",
	{"ALICE", "BARBARA", "CHRIS", "ALFRED", "CLAY", "DAVID", "EDWARD", "CAROL", "AMY", "ELIZABETH", "DANNY",
	"HENRY", "JACLYN", "JAMES", "JANE", "JEFFREY", "JOE", "JOHN", "KIRK", "LAWRENCE", "JUDY", "FREDERICK",
	"LEWIS", "KATIE", "LESLIE", "LINDA", "MARION", "MARK", "LILLIE", "LOUISE", "MARY", "MICHAEL", "PATTY",
	"WILLIAM", "SUSAN", "PHILLIP", "MARTHA", "ROBERT", "TIM"}
);

dt << sort( by( :name ), order( ascending ), replace table( 1 ) );
Jim

Re: Scripting Table Sort by User Defined Column

Just got it on another thread.

1. first add list check

Column( Data Table( "Summary" ),"ITEM") << Set Property(List Check, summary_items);

2. Perform table sort.

 

https://community.jmp.com/t5/Discussions/Custom-Sort-Order/td-p/3119