<?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: Using list of columns in formulas in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Using-list-of-columns-in-formulas/m-p/405632#M65564</link>
    <description>&lt;P&gt;Hi&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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Not sure if this is intended or not, but it's definitely related to the list brackets, {}, and number of items in the list. I could reproduce the same issues you described.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; I think your solution to do the Insert Into is the best choice. The Parse can get very complicated and difficult. I think you have a good solution with the Insert Into and best to stick with that in order to get around the list bracket issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DS&lt;/P&gt;</description>
    <pubDate>Thu, 29 Jul 2021 16:14:27 GMT</pubDate>
    <dc:creator>SDF1</dc:creator>
    <dc:date>2021-07-29T16:14:27Z</dc:date>
    <item>
      <title>Using list of columns in formulas</title>
      <link>https://community.jmp.com/t5/Discussions/Using-list-of-columns-in-formulas/m-p/405133#M65554</link>
      <description>&lt;P&gt;I ran into an "problem" when trying to directly use a column list returned from the column dialog (for example {:sex, :age: name}). When I try to use that list directly in Col formulas (Col Mean, Col Sum...) with byVars the formula won't work correctly. Using the list with for example Sum() formula works fine. &lt;STRONG&gt;Is this intended behaviour and does anyone have cleaner ways to build Col Sums from list of columns than the examples I have below?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is the example script with Sum() and ColSum() formulas. There are couple of different ways I tried to build the ColSum() formulas but managed to get them working only with Insert Into with expressions and EvalParse (which I will try to avoid due to hassle with debugging).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&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 = Open("$SAMPLE_DATA/Big Class.jmp");

dt &amp;lt;&amp;lt; New Column("Sum", Numeric, "Continuous", Format("Best", 12), Formula(Sum(:height, :weight)));
listOfCols = {:height, :weight}; //list works here
dt &amp;lt;&amp;lt; New Column("SumList", &amp;lt;&amp;lt;Formula(Eval(Eval Expr(Sum(Expr(listOfCols))))));

dt &amp;lt;&amp;lt; New Column("ColSum", Numeric, "Continuous", Format("Best", 12), Formula(Col Sum(:height, :age, :sex)));
listOfCols = {:height, :age, :sex}; //won't work here
dt &amp;lt;&amp;lt; New Column("ColSumList", &amp;lt;&amp;lt;Formula(Eval(Eval Expr(Col Mean(Expr(listOfCols))))));

//didnt work either
dt &amp;lt;&amp;lt; New Column("ColSumList2", &amp;lt;&amp;lt;Formula(Eval(Eval Expr(Col Mean(Expr(listOfCols[1]), Expr(listOfCols[2::3]))))));

Show(dt:sum &amp;lt;&amp;lt; get formula);
Show(dt:sumlist &amp;lt;&amp;lt; get formula);
Show(dt:colsum &amp;lt;&amp;lt; get formula);
Show(dt:colsumlist &amp;lt;&amp;lt; get formula);
Show(dt:colsumlist2 &amp;lt;&amp;lt; get formula);

//Insert Into with expressions seems to work, currently best option
formulaExpr = Expr(Col Sum());
For Each({value}, listOfCols, Insert Into(formulaExpr, Name Expr(value)));
dt &amp;lt;&amp;lt; new column("InsertIntoColSum", &amp;lt;&amp;lt; Formula(Eval(EvalExpr(formulaExpr))));
Show(dt:InsertIntoColSum &amp;lt;&amp;lt; get formula);

//I could always EvilParse, but trying to avoid it if possible
Eval(Parse("dt &amp;lt;&amp;lt; New Column(\!"EvilParseColSumList\!", &amp;lt;&amp;lt;Formula(Col Sum(" ||Substitute(char(listOfCols), {"{", "}"}, "") ||")))"));
Show(dt:EvilParseColSumList &amp;lt;&amp;lt; get formula);&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 19:53:36 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Using-list-of-columns-in-formulas/m-p/405133#M65554</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2023-06-09T19:53:36Z</dc:date>
    </item>
    <item>
      <title>Re: Using list of columns in formulas</title>
      <link>https://community.jmp.com/t5/Discussions/Using-list-of-columns-in-formulas/m-p/405632#M65564</link>
      <description>&lt;P&gt;Hi&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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Not sure if this is intended or not, but it's definitely related to the list brackets, {}, and number of items in the list. I could reproduce the same issues you described.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp; I think your solution to do the Insert Into is the best choice. The Parse can get very complicated and difficult. I think you have a good solution with the Insert Into and best to stick with that in order to get around the list bracket issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DS&lt;/P&gt;</description>
      <pubDate>Thu, 29 Jul 2021 16:14:27 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Using-list-of-columns-in-formulas/m-p/405632#M65564</guid>
      <dc:creator>SDF1</dc:creator>
      <dc:date>2021-07-29T16:14:27Z</dc:date>
    </item>
    <item>
      <title>Re: Using list of columns in formulas</title>
      <link>https://community.jmp.com/t5/Discussions/Using-list-of-columns-in-formulas/m-p/424479#M67356</link>
      <description>&lt;P&gt;Again JMP Discovery Summit Meet the Experts delivers! Hopped to&amp;nbsp;&lt;SPAN&gt;Scripting for Automation &amp;amp; Cust breakout room and&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/11257"&gt;@EvanMcCorkle&lt;/a&gt;&amp;nbsp;had way cleaner solution than my looping insert into and eval parse; s&lt;/SPAN&gt;&lt;SPAN&gt;ubstituting the List around listOfCols with ColSum:&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;listOfCols = {:height, :age, :sex}; //won't work here
f =  Substitute(listOfCols, Expr(list), Expr(ColSum));
Show(f); //f = ColSum(:height, :age, :sex);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;SPAN&gt;Not sure if the way Col Sum() functions work with list of columns, but this solution is clean and simple.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 19:04:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Using-list-of-columns-in-formulas/m-p/424479#M67356</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2021-10-07T19:04:08Z</dc:date>
    </item>
  </channel>
</rss>

