cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
FN
FN
Level VI

Sort categorical variables in local data filter (not alphabetically)

I notice that the Local Data Filter for categorical variables shows them in alphabetic order.

 

There is an option to order them by count, but I was after the option of sorting them by other variables.

 

In my case, I have a specific list I want to use as an order, but not sure how to do it.

 

Is there a simpler way than the following?

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
New Window( "Selection Filter",
	Data Filter Context Box(
		H List Box(
			dfsb = Data Filter Source Box(
				Graph Builder(
					Size( 419, 533 ),
					Show Control Panel( 0 ),
					Show Legend( 0 ),
					Variables( Y( :name, Order By( :age, Ascending, Order Statistic( "Mean" ) ) ) ),
					Elements( Bar( Y, Legend( 3 ) ) ),
					SendToReport(
						Dispatch(
							{},
							"Graph Builder",
							OutlineBox,
							{Set Title( "Filter" ), Image Export Display( Normal )}
						)
					)
				);
			),
			Platform(
				Current Data Table(),
				Bubble Plot( X( :weight ), Y( :height ), Sizes( :age ), Title Position( 0, 0 ) )
			)
		)
	)
);

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Sort categorical variables in local data filter (not alphabetically)

Here is a script that uses the default Local Data Filter, along with the Value Order column property to accomplish what you are creating.  The script includes 2 methods for setting the order

txnelson_0-1624710259312.png

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

// If the sorting of the default data table is not an issue this simple code will set 
// the order of the name column to the order found in the data table
/*dt << sort( by( :age ), order( Ascending ), replace table( 1 ) );
dt:name << set property( "value order", {Common Order( 0 ), Row Order Levels( 1 )} );*/

// The code below creates a subset of the default data when it sorts, and then sets the
// Value Order column property to the order found in the sorted data
dtSort = dt << sort( private, by( :age ), order( Ascending ) );
sortList = dtSort:Name << get values;
Close( dtSort, Nosave );
Eval(
	Substitute(
			Expr(
				dt:name << set property(
					"value order",
					{Custom Order( __sList__ ), Common Order( 0 ), Numerical Order( 0 )}
				)
			),
		Expr( __sList__ ), sortList
	)
);

Bubble Plot(
	X( :weight ),
	Y( :height ),
	Sizes( :age ),
	Title Position( 0, 0 ),
	Local Data Filter(
		Add Filter(
			columns( :name ),
			Display( :name, N Items( 15 ), Find( Set Text( "" ) ) )
		)
	),
	SendToReport(
		Dispatch(
			{},
			"weight",
			ScaleBox,
			{Format( "Fixed Dec", 12, 0 ), Min( 60 ), Max( 180 ), Inc( 20 ),
			Minor Ticks( 0 )}
		),
		Dispatch(
			{},
			"height",
			ScaleBox,
			{Format( "Fixed Dec", 12, 0 ), Min( 50 ), Max( 72.5 ), Inc( 5 ),
			Minor Ticks( 1 )}
		)
	)
);


 

Jim

View solution in original post

1 REPLY 1
txnelson
Super User

Re: Sort categorical variables in local data filter (not alphabetically)

Here is a script that uses the default Local Data Filter, along with the Value Order column property to accomplish what you are creating.  The script includes 2 methods for setting the order

txnelson_0-1624710259312.png

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

// If the sorting of the default data table is not an issue this simple code will set 
// the order of the name column to the order found in the data table
/*dt << sort( by( :age ), order( Ascending ), replace table( 1 ) );
dt:name << set property( "value order", {Common Order( 0 ), Row Order Levels( 1 )} );*/

// The code below creates a subset of the default data when it sorts, and then sets the
// Value Order column property to the order found in the sorted data
dtSort = dt << sort( private, by( :age ), order( Ascending ) );
sortList = dtSort:Name << get values;
Close( dtSort, Nosave );
Eval(
	Substitute(
			Expr(
				dt:name << set property(
					"value order",
					{Custom Order( __sList__ ), Common Order( 0 ), Numerical Order( 0 )}
				)
			),
		Expr( __sList__ ), sortList
	)
);

Bubble Plot(
	X( :weight ),
	Y( :height ),
	Sizes( :age ),
	Title Position( 0, 0 ),
	Local Data Filter(
		Add Filter(
			columns( :name ),
			Display( :name, N Items( 15 ), Find( Set Text( "" ) ) )
		)
	),
	SendToReport(
		Dispatch(
			{},
			"weight",
			ScaleBox,
			{Format( "Fixed Dec", 12, 0 ), Min( 60 ), Max( 180 ), Inc( 20 ),
			Minor Ticks( 0 )}
		),
		Dispatch(
			{},
			"height",
			ScaleBox,
			{Format( "Fixed Dec", 12, 0 ), Min( 50 ), Max( 72.5 ), Inc( 5 ),
			Minor Ticks( 1 )}
		)
	)
);


 

Jim