<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Sort Column by column properties in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Sort-Column-by-column-properties/m-p/634996#M83315</link>
    <description>&lt;P&gt;Thanks, Jarmo!&lt;/P&gt;</description>
    <pubDate>Wed, 24 May 2023 17:24:11 GMT</pubDate>
    <dc:creator>Jackie_</dc:creator>
    <dc:date>2023-05-24T17:24:11Z</dc:date>
    <item>
      <title>Sort Column by column properties</title>
      <link>https://community.jmp.com/t5/Discussions/Sort-Column-by-column-properties/m-p/634606#M83261</link>
      <description>&lt;P&gt;Hi JMP Community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to sort the columns by the column property?&lt;/P&gt;&lt;P&gt;I have a data table where the column contains the property "Test Number" (see below).&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to sort all the columns in the column group "Tests" by the column property&amp;nbsp;"Test Number"&lt;/P&gt;&lt;P&gt;I have attached the data table below. Any suggestions?&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Jackie__0-1684875127443.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/53026iD12C968E1D6BD414/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Jackie__0-1684875127443.png" alt="Jackie__0-1684875127443.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Thanks, Jackie!&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2023 20:54:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Sort-Column-by-column-properties/m-p/634606#M83261</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2023-05-23T20:54:33Z</dc:date>
    </item>
    <item>
      <title>Re: Sort Column by column properties</title>
      <link>https://community.jmp.com/t5/Discussions/Sort-Column-by-column-properties/m-p/634630#M83263</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/17878"&gt;@Jackie_&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I expect something like this to work for what you want. The syntax is probably incorrect, but the idea is on the right path. I believe using the associative arrays is the easiest path, since it automatically sorts entries in ascending / alphabetical order inherently.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that I've left &lt;CODE class=" language-jsl"&gt;group_tests_cols&lt;/CODE&gt; empty. I see you've grouped them in "Tests", so you probably have a list, or a method for retrieving all of the column names to create a list.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names default to here(1);

dt = current data table();

group_tests_cols = {  };

// automatically sorts key data in ascending / alphabetical order
aa_tests_cols = Associative Array();

// Puts all of the test numbers as the keys in the AA
for( a = 1, a &amp;lt;= N Items( group_tests_cols ), a++,	
	test_number = column( dt, group_tests_cols[a] ) &amp;lt;&amp;lt; Get Property( "Formula" );	
	eval( eval expr( aa_tests_cols[ expr( test_number ) ] ) ) = group_tests_cols[a];	
);

aa_keys = aa_tests_cols &amp;lt;&amp;lt; Get keys;

// Moves columns in the order of the keys
for( b = 1, b &amp;lt;= N Items( aa_keys ), b++,&lt;BR /&gt;    col_name = aa_tests_cols[ aa_keys[b] ]; // uses index of the key to retrieve the actual value of the key, to get the col name
	eval( eval expr( expr( column( dt, col_name ) ) &amp;lt;&amp;lt; Move Selected Columns( expr( { as column( col_name ) } ), after( :name ) ) ) );
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2023 21:59:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Sort-Column-by-column-properties/m-p/634630#M83263</guid>
      <dc:creator>StarfruitBob</dc:creator>
      <dc:date>2023-05-23T21:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: Sort Column by column properties</title>
      <link>https://community.jmp.com/t5/Discussions/Sort-Column-by-column-properties/m-p/634647#M83267</link>
      <description>&lt;P&gt;Here is a working script that finds the test number values and then orders the columns based upon them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Current Data Table();

//Get the test numbers and the column names associated with them
valList = {};
testList = {};
For Each( {col}, dt &amp;lt;&amp;lt; get column group( "Tests" ),
	Show( col );
	Insert Into( valList, Num( col &amp;lt;&amp;lt; get property( "Test Number" ) ) );
	Insert Into( testList, Char( col &amp;lt;&amp;lt; get name ) );
);

// Sort the test numbers
sortedList = Sort List( valList );

// Loop through the test orders and reorder the columns
For Each( {test, index}, sortedList,
	theCol = Contains( valList, sortedList[N Items( sortedList ) + 1 - index] );
	dt &amp;lt;&amp;lt; go to( testList[theCol] );
	dt &amp;lt;&amp;lt; Move Selected Columns( To first );
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Others may have a better way to accomplish this task&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2023 22:29:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Sort-Column-by-column-properties/m-p/634647#M83267</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2023-05-23T22:29:42Z</dc:date>
    </item>
    <item>
      <title>Re: Sort Column by column properties</title>
      <link>https://community.jmp.com/t5/Discussions/Sort-Column-by-column-properties/m-p/634655#M83269</link>
      <description>&lt;P&gt;Thanks, Jim!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2023 22:35:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Sort-Column-by-column-properties/m-p/634655#M83269</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2023-05-23T22:35:32Z</dc:date>
    </item>
    <item>
      <title>Re: Sort Column by column properties</title>
      <link>https://community.jmp.com/t5/Discussions/Sort-Column-by-column-properties/m-p/634740#M83284</link>
      <description>&lt;P&gt;I think this would work in earlier versions than JMP17&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = Current Data Table();

aa = Associative Array();

For Each({col}, dt &amp;lt;&amp;lt; get column group("Tests"),
	aa[col &amp;lt;&amp;lt; get name] = Num(col &amp;lt;&amp;lt; get property("Test Number"));
);

Eval(EvalExpr(
	dt &amp;lt;&amp;lt; Move Selected Columns(Expr((aa &amp;lt;&amp;lt; get keys)[Rank(aa &amp;lt;&amp;lt; get values)]), To last)
));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In JMP17 (at least JMP17.0) the behaviour of Move Selected Columns was changed (by accident)&amp;nbsp;&lt;LI-MESSAGE title="Any idea why Move Selected Columns works with a list was changed in JMP17?" uid="594187" url="https://community.jmp.com/t5/Discussions/Any-idea-why-Move-Selected-Columns-works-with-a-list-was-changed/m-p/594187#U594187" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-forum-thread lia-fa-icon lia-fa-forum lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 May 2023 10:20:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Sort-Column-by-column-properties/m-p/634740#M83284</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-05-24T10:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: Sort Column by column properties</title>
      <link>https://community.jmp.com/t5/Discussions/Sort-Column-by-column-properties/m-p/634996#M83315</link>
      <description>&lt;P&gt;Thanks, Jarmo!&lt;/P&gt;</description>
      <pubDate>Wed, 24 May 2023 17:24:11 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Sort-Column-by-column-properties/m-p/634996#M83315</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2023-05-24T17:24:11Z</dc:date>
    </item>
    <item>
      <title>Re: Sort Column by column properties</title>
      <link>https://community.jmp.com/t5/Discussions/Sort-Column-by-column-properties/m-p/663012#M85173</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;I on JMP 17 and the move select doesn't work.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Muliple Move Selected Columns commands wouldn't be robust per&lt;A href="https://community.jmp.com/t5/Discussions/Any-idea-why-Move-Selected-Columns-works-with-a-list-was-changed/m-p/594187#U594187" target="_blank" rel="noopener"&gt;Any idea why Move Selected Columns works with a list was changed in JMP17?&lt;/A&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any workaround that you can suggest for this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class="language-jsl"&gt;&lt;CODE&gt;Names Default To Here( 1 );
dt = Current Data Table();

aa = Associative Array();

For Each({col}, dt &amp;lt;&amp;lt; get column group("Tests"),
	aa[col &amp;lt;&amp;lt; get name] = Num(col &amp;lt;&amp;lt; get property("Test Number"));
);

Eval(EvalExpr(
	dt &amp;lt;&amp;lt; Move Selected Columns(Expr((aa &amp;lt;&amp;lt; get keys)[Rank(aa &amp;lt;&amp;lt; get values)]), To last)
));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2023 16:36:47 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Sort-Column-by-column-properties/m-p/663012#M85173</guid>
      <dc:creator>Jackie_</dc:creator>
      <dc:date>2023-07-27T16:36:47Z</dc:date>
    </item>
    <item>
      <title>Re: Sort Column by column properties</title>
      <link>https://community.jmp.com/t5/Discussions/Sort-Column-by-column-properties/m-p/663064#M85179</link>
      <description>&lt;P&gt;Performing multiple move selected columns within a loop should work. You just have to first create the ordering list for the columns and then loop accordingly&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2023 17:55:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Sort-Column-by-column-properties/m-p/663064#M85179</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-07-27T17:55:59Z</dc:date>
    </item>
  </channel>
</rss>

