<?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: How to make a formula that can take in a variable number of input columns? in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/How-to-make-a-formula-that-can-take-in-a-variable-number-of/m-p/869636#M103238</link>
    <description>&lt;P&gt;"centering columns" - this is needed very often. There are hundreds of combinations how to center (divide of subtract) and how to calculate the "reference":&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_1-1745382025838.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/75095i7B7BD4618DEBB1D3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_1-1745382025838.png" alt="hogi_1-1745382025838.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;You can have a look at&amp;nbsp;&lt;A href="https://marketplace.jmp.com/appdetails/Normalization+GUI" target="_blank"&gt;https://marketplace.jmp.com/appdetails/Normalization+GUI&lt;/A&gt;&amp;nbsp;- it adds a GUI to the JMP menu to do the job for you. It also works if rows are excluded.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to set it up on you own, the basic idea is to manipulate the expressions step by step.&lt;BR /&gt;e.g. use &lt;FONT face="courier new,courier"&gt;Insert Into&lt;/FONT&gt; to add a dynamic number of grouping columns:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For Each( {groupByCol, idx}, currentGroupCols,
	Insert Into( secondArgumentDirect, Name Expr( As Column( dt, groupByCol ) ) )
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 23 Apr 2025 04:36:43 GMT</pubDate>
    <dc:creator>hogi</dc:creator>
    <dc:date>2025-04-23T04:36:43Z</dc:date>
    <item>
      <title>How to make a formula that can take in a variable number of input columns?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-a-formula-that-can-take-in-a-variable-number-of/m-p/869624#M103237</link>
      <description>&lt;P&gt;Hey everyone,&lt;/P&gt;
&lt;P&gt;I have a script I made to center a data column by a grouping column:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="shampton82_0-1745378504833.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/75093i3EC71EABA5E4968A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="shampton82_0-1745378504833.png" alt="shampton82_0-1745378504833.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Right now it only respects one centered by column but I'd like to be able to put in multiple columns.&amp;nbsp; Any guidance on how to make the formula more dynamic?&amp;nbsp; Currently I just use this to start a new column then go in and manually add the addition columns to center by.&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();


results = Column Dialog(src=ColList("Cols to be centered", Min Col(1)),trg = ColList("centered by", Min Col(1)));

for(i=1, i&amp;lt;= n items(eval(results[1])), i++,
	ts=expr(dt &amp;lt;&amp;lt; New Column( "cent col", "Numeric",Formula(Expr(Eval( results[1] )[i]) - Col Mean( Expr(Eval( results[1] )[i]), Expr(Eval( results[2] )[1]) ))));
	eval(eval expr(TS));

	ts=expr(dt:"cent col"n&amp;lt;&amp;lt;set name(char(Eval( results[1] )[i])||" centered by "||char(Eval( results[2] )[1])));
	eval(eval expr(TS));
	
);
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks for any input!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Apr 2025 03:25:17 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-a-formula-that-can-take-in-a-variable-number-of/m-p/869624#M103237</guid>
      <dc:creator>shampton82</dc:creator>
      <dc:date>2025-04-23T03:25:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a formula that can take in a variable number of input columns?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-a-formula-that-can-take-in-a-variable-number-of/m-p/869636#M103238</link>
      <description>&lt;P&gt;"centering columns" - this is needed very often. There are hundreds of combinations how to center (divide of subtract) and how to calculate the "reference":&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="hogi_1-1745382025838.png" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/75095i7B7BD4618DEBB1D3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="hogi_1-1745382025838.png" alt="hogi_1-1745382025838.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;You can have a look at&amp;nbsp;&lt;A href="https://marketplace.jmp.com/appdetails/Normalization+GUI" target="_blank"&gt;https://marketplace.jmp.com/appdetails/Normalization+GUI&lt;/A&gt;&amp;nbsp;- it adds a GUI to the JMP menu to do the job for you. It also works if rows are excluded.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to set it up on you own, the basic idea is to manipulate the expressions step by step.&lt;BR /&gt;e.g. use &lt;FONT face="courier new,courier"&gt;Insert Into&lt;/FONT&gt; to add a dynamic number of grouping columns:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For Each( {groupByCol, idx}, currentGroupCols,
	Insert Into( secondArgumentDirect, Name Expr( As Column( dt, groupByCol ) ) )
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Apr 2025 04:36:43 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-a-formula-that-can-take-in-a-variable-number-of/m-p/869636#M103238</guid>
      <dc:creator>hogi</dc:creator>
      <dc:date>2025-04-23T04:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a formula that can take in a variable number of input columns?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-a-formula-that-can-take-in-a-variable-number-of/m-p/869637#M103239</link>
      <description>&lt;P&gt;Do you mean you wish to add more grouping columns?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
dt = Current Data Table();


results = Column Dialog(
	src=ColList("Cols to be centered", Min Col(1)),
	trg = ColList("centered by", Min Col(1))
);

srcs = results["src"];
trgs = results["trg"];

For Each({src}, srcs,
	colname = (src &amp;lt;&amp;lt; get name) || " centered by";
	
	mean_expr = Expr(Col Mean());
	Insert Into(mean_expr, NameExpr(src));
	For Each({trg}, trgs,
		colname = colname || " " || (trg &amp;lt;&amp;lt; get name);
		Insert Into(mean_expr, NameExpr(trg));
	);

	Eval(Substitute(
		Expr(dt &amp;lt;&amp;lt; New Column(colname, "Numeric", "Continuous", Formula(
			_col1_ - _mean_
		));
		),
		Expr(_col1_), Name Expr(src),
		Expr(_mean_), Name Expr(mean_expr),
	));
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Optionally you could also let JMP do more of this by using New Formula Column and changing names after&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
dt = Current Data Table();


results = Column Dialog(
	src=ColList("Cols to be centered", Min Col(1)),
	trg = ColList("centered by", Min Col(1))
);

srcs = results["src"];
trgs = results["trg"];

res = dt &amp;lt;&amp;lt; New Formula Column(
	Operation(Category("Distributional"), "Center"),
	Columns(srcs),
	Group By(trgs)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Apr 2025 04:41:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-a-formula-that-can-take-in-a-variable-number-of/m-p/869637#M103239</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-04-23T04:41:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a formula that can take in a variable number of input columns?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-a-formula-that-can-take-in-a-variable-number-of/m-p/869758#M103265</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/26800"&gt;@hogi&lt;/a&gt;&amp;nbsp;.&amp;nbsp; I'll have to get that add in.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ah "Insert Into", thats looks to be the ticket (as&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;goes into as well).&lt;/P&gt;</description>
      <pubDate>Wed, 23 Apr 2025 14:09:35 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-a-formula-that-can-take-in-a-variable-number-of/m-p/869758#M103265</guid>
      <dc:creator>shampton82</dc:creator>
      <dc:date>2025-04-23T14:09:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a formula that can take in a variable number of input columns?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-a-formula-that-can-take-in-a-variable-number-of/m-p/869760#M103266</link>
      <description>&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Yeah it would be able to add in more grouping columns and the first script is perfect!&amp;nbsp; Thanks for the help!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Apr 2025 14:12:11 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-a-formula-that-can-take-in-a-variable-number-of/m-p/869760#M103266</guid>
      <dc:creator>shampton82</dc:creator>
      <dc:date>2025-04-23T14:12:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a formula that can take in a variable number of input columns?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-a-formula-that-can-take-in-a-variable-number-of/m-p/869771#M103271</link>
      <description>&lt;P&gt;One option is also using Substitute to replace some expression with Col Mean &lt;LI-MESSAGE title="Using list of columns in formulas" uid="405133" url="https://community.jmp.com/t5/Discussions/Using-list-of-columns-in-formulas/m-p/405133#U405133" 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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is lazy example with your data&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1);
dt = Current Data Table();


results = Column Dialog(
	src=ColList("Cols to be centered", Min Col(1)),
	trg = ColList("centered by", Min Col(1))
);

srcs = results["src"];
trgs = results["trg"];


For Each({src}, srcs,
	colname = (src &amp;lt;&amp;lt; get name) || " centered by";
	l = Insert(trgs, Name Expr(src), 1);
	f = Substitute(l, Expr(List), Expr(Col Mean()));

	Eval(Substitute(
		Expr(dt &amp;lt;&amp;lt; New Column(colname, "Numeric", "Continuous", Formula(
			_col1_ - _mean_
		));
		),
		Expr(_col1_), Name Expr(src),
		Expr(_mean_), Name Expr(f),
	));	
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Just one note: I would build the dialog using New Window instead of using Column Dialog as it gives much more flexibility even in fairly simple cases.&lt;/P&gt;</description>
      <pubDate>Wed, 23 Apr 2025 14:39:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-a-formula-that-can-take-in-a-variable-number-of/m-p/869771#M103271</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-04-23T14:39:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to make a formula that can take in a variable number of input columns?</title>
      <link>https://community.jmp.com/t5/Discussions/How-to-make-a-formula-that-can-take-in-a-variable-number-of/m-p/869947#M103298</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/14366"&gt;@jthi&lt;/a&gt;&amp;nbsp;for the added options.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yeah this was an older script where I hadn't switched over to using new window so I've fixed that bad habit now!&lt;/P&gt;</description>
      <pubDate>Thu, 24 Apr 2025 04:08:02 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/How-to-make-a-formula-that-can-take-in-a-variable-number-of/m-p/869947#M103298</guid>
      <dc:creator>shampton82</dc:creator>
      <dc:date>2025-04-24T04:08:02Z</dc:date>
    </item>
  </channel>
</rss>

