<?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: JSL: how to group all columns by common initial term? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/JSL-how-to-group-all-columns-by-common-initial-term/m-p/681878#M86755</link>
    <description>&lt;P&gt;There are many ways of doing this. I have used something similar as I demonstrate in below script (using associative array)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Probe.jmp");

aa_groups = ["DELL" =&amp;gt; {}, "DELW" =&amp;gt; {}, "RCON" =&amp;gt; {}];
col_names = dt &amp;lt;&amp;lt; Get Column Names("String");

For Each({col_name}, col_names,
	For Each({{key, value}}, aa_groups,
		If(Starts With(col_name, key ||"_"), // "_" is used as additional separator
			Insert Into(aa_groups[key], col_name);
			Break();
		)
	);
);

For Each({{groupname, groupcols}}, aa_groups,
	dt &amp;lt;&amp;lt; Group Columns(groupname, groupcols);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you need to go more dynamic you can also do that&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Probe.jmp");

aa_groups = Associative Array();
col_names = dt &amp;lt;&amp;lt; Get Column Names("String");

For Each({col_name}, col_names,
	nameparts = Words(col_name, "_"); // depending ion your columns, this might need to change
	If(N Items(nameparts) &amp;gt; 1,
		If(!Contains(aa_groups, nameparts[1]),
			aa_groups[nameparts[1]] = {}; // add new key
		);
		Insert Into(aa_groups[nameparts[1]], col_name);
	);
);

For Each({{groupname, groupcols}}, aa_groups,
	dt &amp;lt;&amp;lt; Group Columns(groupname, groupcols);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Idea is the same in both. Create associative array where they keys are column group names and the values are list of columns which belong to that group.&lt;/P&gt;</description>
    <pubDate>Thu, 28 Sep 2023 05:43:06 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2023-09-28T05:43:06Z</dc:date>
    <item>
      <title>JSL: how to group all columns by common initial term?</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-how-to-group-all-columns-by-common-initial-term/m-p/681834#M86747</link>
      <description>&lt;P&gt;I've got a dt (70k cols) that I'd like to group into common bundles, based on the initial delineated terms.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, 10K cols each that all start with "ChamberID", or "RecipeID", or "SlotNo".&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I script this to churn through the dt to find all common cols, group them into a collapsible bundle?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="LambdaMarmoset7_0-1695859115637.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/57049i0BAE7DB8E6949D56/image-size/medium?v=v2&amp;amp;px=400" role="button" title="LambdaMarmoset7_0-1695859115637.png" alt="LambdaMarmoset7_0-1695859115637.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Sep 2023 23:58:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-how-to-group-all-columns-by-common-initial-term/m-p/681834#M86747</guid>
      <dc:creator>LambdaMarmoset7</dc:creator>
      <dc:date>2023-09-27T23:58:45Z</dc:date>
    </item>
    <item>
      <title>Re: JSL: how to group all columns by common initial term?</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-how-to-group-all-columns-by-common-initial-term/m-p/681844#M86748</link>
      <description>&lt;P&gt;Here is a little script that is an example of creating Column Groups in a data table.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="txnelson_0-1695861708511.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/57050iC258B72EEC85CC6A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="txnelson_0-1695861708511.png" alt="txnelson_0-1695861708511.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

dt = 
// Open Data Table: semiconductor capability.jmp
// → Data Table( "semiconductor capability" )
Open( "$SAMPLE_DATA/semiconductor capability.jmp" );

colNames = dt &amp;lt;&amp;lt; get column names( string, continuous );

group1 = {};
group2 = {};
For Each( {name}, colNames,
	/*If(
		Left( name, 9 ) == "ChamberID",
			Insert Into( group1, name ),
		Left( name, 8 ) == "RecipeID",
			Insert Into( group2, name )
	)*/
	If(
		Left( name, 3 ) == "NPN",
			Insert Into( group1, name ),
		Left( name, 3 ) == "PNP",
			Insert Into( group2, name )
	)
);

dt &amp;lt;&amp;lt; group columns( "NPN", group1);
dt &amp;lt;&amp;lt; group columns( "PNP", group2);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Sep 2023 00:42:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-how-to-group-all-columns-by-common-initial-term/m-p/681844#M86748</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2023-09-28T00:42:15Z</dc:date>
    </item>
    <item>
      <title>Re: JSL: how to group all columns by common initial term?</title>
      <link>https://community.jmp.com/t5/Discussions/JSL-how-to-group-all-columns-by-common-initial-term/m-p/681878#M86755</link>
      <description>&lt;P&gt;There are many ways of doing this. I have used something similar as I demonstrate in below script (using associative array)&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Probe.jmp");

aa_groups = ["DELL" =&amp;gt; {}, "DELW" =&amp;gt; {}, "RCON" =&amp;gt; {}];
col_names = dt &amp;lt;&amp;lt; Get Column Names("String");

For Each({col_name}, col_names,
	For Each({{key, value}}, aa_groups,
		If(Starts With(col_name, key ||"_"), // "_" is used as additional separator
			Insert Into(aa_groups[key], col_name);
			Break();
		)
	);
);

For Each({{groupname, groupcols}}, aa_groups,
	dt &amp;lt;&amp;lt; Group Columns(groupname, groupcols);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you need to go more dynamic you can also do that&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Probe.jmp");

aa_groups = Associative Array();
col_names = dt &amp;lt;&amp;lt; Get Column Names("String");

For Each({col_name}, col_names,
	nameparts = Words(col_name, "_"); // depending ion your columns, this might need to change
	If(N Items(nameparts) &amp;gt; 1,
		If(!Contains(aa_groups, nameparts[1]),
			aa_groups[nameparts[1]] = {}; // add new key
		);
		Insert Into(aa_groups[nameparts[1]], col_name);
	);
);

For Each({{groupname, groupcols}}, aa_groups,
	dt &amp;lt;&amp;lt; Group Columns(groupname, groupcols);
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Idea is the same in both. Create associative array where they keys are column group names and the values are list of columns which belong to that group.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Sep 2023 05:43:06 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/JSL-how-to-group-all-columns-by-common-initial-term/m-p/681878#M86755</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-09-28T05:43:06Z</dc:date>
    </item>
  </channel>
</rss>

