<?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: Group Columns by a list of values from another column? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Group-Columns-by-a-list-of-values-from-another-column/m-p/462315#M70711</link>
    <description>&lt;P&gt;If your column names(?)&amp;nbsp; have always step1_something format, you could use Word to separate the step from rest of the string to make comparison easier. Below is an example of what I think you would like to do (requires JMP16 due to For Each):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = New Table("Untitled",
	Add Rows(3),
	Set Header Height(44),
	New Column("Col1", Character, "Nominal", Set Values({"step1", "step2", "step3"})),
	New Column("step1_a", Numeric, "Continuous", Format("Best", 12), Set Values([., ., .])),
	New Column("step1_b", Numeric, "Continuous", Format("Best", 12), Set Values([., ., .])),
	New Column("step1_c", Numeric, "Continuous", Format("Best", 12), Set Values([., ., .])),
	New Column("step2_a", Numeric, "Continuous", Format("Best", 12), Set Values([., ., .])),
	New Column("step2_b", Numeric, "Continuous", Format("Best", 12), Set Values([., ., .]))
);

Summarize(dt, uniq_vals = by(:col1)); 
col_list = dt &amp;lt;&amp;lt; get column names(string, continuous);

//initialize col group collector associative array
col_groups = Repeat({{}}, N Items(uniq_vals));

For Each({col_name}, col_list,
	found_idx = Contains(uniq_vals, Word(1, col_name, "_"));
	If(found_idx,
		Insert Into(col_groups[found_idx], col_name);
	);
);

For Each({col_group, idx}, uniq_vals,
	If(N Items(col_groups[idx]) &amp;gt; 0,
		Eval(EvalExpr(dt &amp;lt;&amp;lt; Group Columns(col_group, Expr(col_groups[idx]))));
	);
);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 18 Feb 2022 22:39:33 GMT</pubDate>
    <dc:creator>jthi</dc:creator>
    <dc:date>2022-02-18T22:39:33Z</dc:date>
    <item>
      <title>Group Columns by a list of values from another column?</title>
      <link>https://community.jmp.com/t5/Discussions/Group-Columns-by-a-list-of-values-from-another-column/m-p/462295#M70709</link>
      <description>&lt;P&gt;I'm working to group several thousand columns together by name that matches with something from a list of values from an initial column&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;example:&lt;/P&gt;&lt;P&gt;Col1 values = {step1, step2, step3}&lt;/P&gt;&lt;P&gt;Col2:5000 names :step1_blahblahblah, step2_blahblbahblah, etc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I guess I'm not quite sure how to define the if(contain) statement uses the list of values from Col1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;dt = current data table();
Summarize( dt, StepIDIndex= by( :RecipeStepId) );//get list of unique RecipeStepID's
colNamesList = dt &amp;lt;&amp;lt; get column names(string, continuous);  //get all the column names
StepList = {}; //Create an empty list for the matching columns

// Find matching column names
For( i = 1, i &amp;lt;= N Items( colNamesList ), i++,
	If( 
		contains( colNamesList[i], StepIDIndex),
		Insert Into( StepList , colNamesList[i] )
	)
);

// If groups of columns are found, create col groupings
If( N Items( StepList ) &amp;gt; 0,
	dt&amp;lt;&amp;lt; select columns( StepList );
	dt&amp;lt;&amp;lt; group columns();
);

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 18:11:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Group-Columns-by-a-list-of-values-from-another-column/m-p/462295#M70709</guid>
      <dc:creator>aliegner1</dc:creator>
      <dc:date>2023-06-09T18:11:07Z</dc:date>
    </item>
    <item>
      <title>Re: Group Columns by a list of values from another column?</title>
      <link>https://community.jmp.com/t5/Discussions/Group-Columns-by-a-list-of-values-from-another-column/m-p/462315#M70711</link>
      <description>&lt;P&gt;If your column names(?)&amp;nbsp; have always step1_something format, you could use Word to separate the step from rest of the string to make comparison easier. Below is an example of what I think you would like to do (requires JMP16 due to For Each):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);

dt = New Table("Untitled",
	Add Rows(3),
	Set Header Height(44),
	New Column("Col1", Character, "Nominal", Set Values({"step1", "step2", "step3"})),
	New Column("step1_a", Numeric, "Continuous", Format("Best", 12), Set Values([., ., .])),
	New Column("step1_b", Numeric, "Continuous", Format("Best", 12), Set Values([., ., .])),
	New Column("step1_c", Numeric, "Continuous", Format("Best", 12), Set Values([., ., .])),
	New Column("step2_a", Numeric, "Continuous", Format("Best", 12), Set Values([., ., .])),
	New Column("step2_b", Numeric, "Continuous", Format("Best", 12), Set Values([., ., .]))
);

Summarize(dt, uniq_vals = by(:col1)); 
col_list = dt &amp;lt;&amp;lt; get column names(string, continuous);

//initialize col group collector associative array
col_groups = Repeat({{}}, N Items(uniq_vals));

For Each({col_name}, col_list,
	found_idx = Contains(uniq_vals, Word(1, col_name, "_"));
	If(found_idx,
		Insert Into(col_groups[found_idx], col_name);
	);
);

For Each({col_group, idx}, uniq_vals,
	If(N Items(col_groups[idx]) &amp;gt; 0,
		Eval(EvalExpr(dt &amp;lt;&amp;lt; Group Columns(col_group, Expr(col_groups[idx]))));
	);
);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Feb 2022 22:39:33 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Group-Columns-by-a-list-of-values-from-another-column/m-p/462315#M70711</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2022-02-18T22:39:33Z</dc:date>
    </item>
  </channel>
</rss>

