<?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 Sum all Columns that contain a string in the column name in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Sum-all-Columns-that-contain-a-string-in-the-column-name/m-p/6514#M6508</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to take a data table and add a column with a formula that sums all columns that contain the string "ToAdd" in the column name. I'm trying to script this because the columns that will have "ToAdd" somewhere in the name will change.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So far, I have the script that can collect all the column names into a list, but I'm not sure how to then use that list to generate a new column with a formula that sums all those columns together. This seemed like the best way to start, but not sure where to go from here (or if it really is a good way to start)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;dt = current data table();&lt;/P&gt;&lt;P&gt;N = N Col( dt );&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;AddColumns = {};&lt;/P&gt;&lt;P&gt;For( i=1, i &amp;lt;= N, i++,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; colname = Column(i) &amp;lt;&amp;lt; getname();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If( Contains( colname, "ToAdd") &amp;gt; 1,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Insert Into(AddColumns, colname )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; );&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;/P&gt;&lt;P&gt;);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for any help in advance!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 05 Apr 2013 23:02:25 GMT</pubDate>
    <dc:creator>dfmoore</dc:creator>
    <dc:date>2013-04-05T23:02:25Z</dc:date>
    <item>
      <title>Sum all Columns that contain a string in the column name</title>
      <link>https://community.jmp.com/t5/Discussions/Sum-all-Columns-that-contain-a-string-in-the-column-name/m-p/6514#M6508</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to take a data table and add a column with a formula that sums all columns that contain the string "ToAdd" in the column name. I'm trying to script this because the columns that will have "ToAdd" somewhere in the name will change.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So far, I have the script that can collect all the column names into a list, but I'm not sure how to then use that list to generate a new column with a formula that sums all those columns together. This seemed like the best way to start, but not sure where to go from here (or if it really is a good way to start)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;dt = current data table();&lt;/P&gt;&lt;P&gt;N = N Col( dt );&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;AddColumns = {};&lt;/P&gt;&lt;P&gt;For( i=1, i &amp;lt;= N, i++,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; colname = Column(i) &amp;lt;&amp;lt; getname();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If( Contains( colname, "ToAdd") &amp;gt; 1,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Insert Into(AddColumns, colname )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; );&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;/P&gt;&lt;P&gt;);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for any help in advance!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Apr 2013 23:02:25 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Sum-all-Columns-that-contain-a-string-in-the-column-name/m-p/6514#M6508</guid>
      <dc:creator>dfmoore</dc:creator>
      <dc:date>2013-04-05T23:02:25Z</dc:date>
    </item>
    <item>
      <title>Re: Sum all Columns that contain a string in the column name</title>
      <link>https://community.jmp.com/t5/Discussions/Sum-all-Columns-that-contain-a-string-in-the-column-name/m-p/6515#M6509</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It's a good start. To set column formulas by script, however, is a bit tricky as the argument is interpreted literally. Building a formula dynamically usually involves building strings or expressions that finally is parsed/evaluated. Otherwise local or session-specific variables will end up in the formula and it will not work as expected. At least that is my experience.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's an example using the string approach:&lt;/P&gt;&lt;P style="font-size: 12px; font-family: Courier; color: #032ce4;"&gt;&lt;SPAN style="color: #000000;"&gt;dt &lt;/SPAN&gt;&lt;SPAN style="color: #011993;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt; &lt;/SPAN&gt;Current Data Table&lt;SPAN style="color: #000000;"&gt;&lt;STRONG&gt;()&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #011993;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; font-family: Courier;"&gt;N &lt;SPAN style="color: #011993;"&gt;=&lt;/SPAN&gt; &lt;SPAN style="color: #032ce4;"&gt;N Col&lt;/SPAN&gt;&lt;STRONG&gt;(&lt;/STRONG&gt; dt &lt;STRONG&gt;)&lt;/STRONG&gt;&lt;SPAN style="color: #011993;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; font-family: Courier;"&gt;s &lt;SPAN style="color: #011993;"&gt;=&lt;/SPAN&gt; &lt;SPAN style="color: #942193;"&gt;""&lt;/SPAN&gt;&lt;SPAN style="color: #011993;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; font-family: Courier;"&gt;&lt;SPAN style="color: #032ce4;"&gt;For&lt;/SPAN&gt;&lt;STRONG&gt;(&lt;/STRONG&gt; i &lt;SPAN style="color: #011993;"&gt;=&lt;/SPAN&gt; &lt;SPAN style="color: #009193;"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #011993;"&gt;,&lt;/SPAN&gt; i &lt;SPAN style="color: #011993;"&gt;&amp;lt;=&lt;/SPAN&gt; N&lt;SPAN style="color: #011993;"&gt;,&lt;/SPAN&gt; i&lt;SPAN style="color: #011993;"&gt;++,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; font-family: Courier;"&gt;&amp;nbsp; colname &lt;SPAN style="color: #011993;"&gt;=&lt;/SPAN&gt; &lt;SPAN style="color: #032ce4;"&gt;Column&lt;/SPAN&gt;&lt;STRONG&gt;(&lt;/STRONG&gt; i &lt;STRONG&gt;)&lt;/STRONG&gt; &lt;SPAN style="color: #011993;"&gt;&amp;lt;&amp;lt;&lt;/SPAN&gt; getname&lt;STRONG&gt;()&lt;/STRONG&gt;&lt;SPAN style="color: #011993;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; font-family: Courier;"&gt;&amp;nbsp; &lt;SPAN style="color: #032ce4;"&gt;If&lt;/SPAN&gt;&lt;STRONG&gt;(&lt;/STRONG&gt; &lt;SPAN style="color: #032ce4;"&gt;Contains&lt;/SPAN&gt;&lt;STRONG&gt;(&lt;/STRONG&gt; colname&lt;SPAN style="color: #011993;"&gt;,&lt;/SPAN&gt; &lt;SPAN style="color: #942193;"&gt;"ToAdd"&lt;/SPAN&gt; &lt;STRONG&gt;)&lt;/STRONG&gt; &lt;SPAN style="color: #011993;"&gt;&amp;gt;&lt;/SPAN&gt; &lt;SPAN style="color: #009193;"&gt;&lt;STRONG&gt;0&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #011993;"&gt;,&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; font-family: Courier;"&gt;&amp;nbsp; s &lt;SPAN style="color: #011993;"&gt;=&lt;/SPAN&gt; s &lt;SPAN style="color: #011993;"&gt;||&lt;/SPAN&gt; &lt;SPAN style="color: #032ce4;"&gt;If&lt;/SPAN&gt;&lt;STRONG&gt;(&lt;/STRONG&gt; &lt;SPAN style="color: #032ce4;"&gt;Length&lt;/SPAN&gt;&lt;STRONG&gt;(&lt;/STRONG&gt; s &lt;STRONG&gt;)&lt;/STRONG&gt; &lt;SPAN style="color: #011993;"&gt;&amp;gt;&lt;/SPAN&gt; &lt;SPAN style="color: #009193;"&gt;&lt;STRONG&gt;0&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #011993;"&gt;,&lt;/SPAN&gt; &lt;SPAN style="color: #942193;"&gt;", "&lt;/SPAN&gt;&lt;SPAN style="color: #011993;"&gt;,&lt;/SPAN&gt; &lt;SPAN style="color: #942193;"&gt;""&lt;/SPAN&gt; &lt;STRONG&gt;)&lt;/STRONG&gt; &lt;SPAN style="color: #011993;"&gt;||&lt;/SPAN&gt; colname&lt;/P&gt;&lt;P style="font-size: 12px; font-family: Courier;"&gt;&amp;nbsp; &lt;STRONG&gt;)&lt;/STRONG&gt;&lt;SPAN style="color: #011993;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; font-family: Courier;"&gt;&lt;STRONG&gt;)&lt;/STRONG&gt;&lt;SPAN style="color: #011993;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; font-family: Courier; color: #032ce4;"&gt;show&lt;SPAN style="color: #000000;"&gt;&lt;STRONG&gt;(&lt;/STRONG&gt;s&lt;STRONG&gt;)&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #011993;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; font-family: Courier;"&gt;col &lt;SPAN style="color: #011993;"&gt;=&lt;/SPAN&gt; dt &lt;SPAN style="color: #011993;"&gt;&amp;lt;&amp;lt;&lt;/SPAN&gt; &lt;SPAN style="color: #032ce4;"&gt;New Column&lt;/SPAN&gt;&lt;STRONG&gt;(&lt;/STRONG&gt; &lt;SPAN style="color: #942193;"&gt;"Sum(AddColumns)"&lt;/SPAN&gt;&lt;SPAN style="color: #011993;"&gt;,&lt;/SPAN&gt; numeric &lt;STRONG&gt;)&lt;/STRONG&gt;&lt;SPAN style="color: #011993;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-size: 12px; font-family: Courier; color: #942193;"&gt;&lt;SPAN style="color: #032ce4;"&gt;Eval&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&lt;STRONG&gt;(&lt;/STRONG&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #032ce4;"&gt;Parse&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&lt;STRONG&gt;(&lt;/STRONG&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #032ce4;"&gt;Eval Insert&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;&lt;STRONG&gt;(&lt;/STRONG&gt; &lt;/SPAN&gt;"col&amp;lt;&amp;lt;set formula(sum(^s^))"&lt;SPAN style="color: #000000;"&gt; &lt;STRONG&gt;)&lt;/STRONG&gt; &lt;STRONG&gt;)&lt;/STRONG&gt; &lt;STRONG&gt;)&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #011993;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 06 Apr 2013 00:47:57 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Sum-all-Columns-that-contain-a-string-in-the-column-name/m-p/6515#M6509</guid>
      <dc:creator>ms</dc:creator>
      <dc:date>2013-04-06T00:47:57Z</dc:date>
    </item>
    <item>
      <title>Re: Sum all Columns that contain a string in the column name</title>
      <link>https://community.jmp.com/t5/Discussions/Sum-all-Columns-that-contain-a-string-in-the-column-name/m-p/6516#M6510</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Works like a charm!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 06 Apr 2013 14:38:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Sum-all-Columns-that-contain-a-string-in-the-column-name/m-p/6516#M6510</guid>
      <dc:creator>dfmoore</dc:creator>
      <dc:date>2013-04-06T14:38:41Z</dc:date>
    </item>
  </channel>
</rss>

