<?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: Parse a concatenated string which has comma in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Parse-a-concatenated-string-which-has-comma/m-p/271681#M52885</link>
    <description>&lt;P&gt;Thank you for helping and the explanation! The "Yet Another Data" column in your script does exactly what i want. The "Another Data" column seems to be returning an empty cell with an error "need arguments to be scalars, matrices, or lists..". I will try to figure out why this is happening.&lt;/P&gt;</description>
    <pubDate>Tue, 09 Jun 2020 19:11:13 GMT</pubDate>
    <dc:creator>noviJSL</dc:creator>
    <dc:date>2020-06-09T19:11:13Z</dc:date>
    <item>
      <title>Parse a concatenated string which has comma</title>
      <link>https://community.jmp.com/t5/Discussions/Parse-a-concatenated-string-which-has-comma/m-p/271511#M52854</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I have a datatable with multiple columns, some of which I want to add together. As a part of my script, I am selecting some of the columns, storing the column names in a list and then hoping to add the selected columns using the "Sum" feature.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In order to do that I need to build a string&amp;nbsp;":DATA1, :DATA2, :DATA3" and Parse it in a column.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;New Column( "Addition", Numeric, Continuous, Formula( Parse( Sum( :DATA1, :DATA2, :DATA3 ) ) ) );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A snippet of the code I am using is below:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;New Column( "Addition", Numeric, Continuous, Formula( Parse( Sum( :DATA1, :DATA2, :DATA3 ) ) ) );
list = {"DATA1", "DATA2", "DATA3"};
For( i = 1, i &amp;lt;= N Items( list ), i++,
    If(
        i == 1, string = ":" || Char( Eval( list[Eval( i )] ) ),
        i &amp;gt; 1, string = string || "," || ":" || Char( Eval( list[Eval( i )] ) )
    )
);
Parse( string );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On execution, I get the following error:&lt;/P&gt;
&lt;P&gt;Unexpected ",". Perhaps there is a missing ";" or ",".&lt;BR /&gt;Line 1 Column 7: :DATA1►,:DATA2,:DATA3&lt;/P&gt;
&lt;P&gt;The remaining text that was ignored was&lt;BR /&gt;,:DATA2,:DATA3&lt;BR /&gt;:DATA1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there anything I am missing?&lt;/P&gt;
&lt;P&gt;Thanks in advance!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 23:28:34 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Parse-a-concatenated-string-which-has-comma/m-p/271511#M52854</guid>
      <dc:creator>noviJSL</dc:creator>
      <dc:date>2023-06-09T23:28:34Z</dc:date>
    </item>
    <item>
      <title>Re: Parse a concatenated string which has comma</title>
      <link>https://community.jmp.com/t5/Discussions/Parse-a-concatenated-string-which-has-comma/m-p/271515#M52857</link>
      <description>&lt;P&gt;Look at the string in which it returns.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;":DATA1,:DATA2,:DATA3"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try running just that without the quotes, you'll get the same thing.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have column names as strings, you can do something like this.&amp;nbsp;&amp;nbsp;&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 = New Table( "Example",
	Add Rows( 1 ),
	New Column( "Data1", Set Values( [1] )),
	New Column( "Data2", Set Values( [2] )),
	New Column( "Data3", Set Values( [3] )),
);
// list of column names as strings
list = dt &amp;lt;&amp;lt; Get Column Names("string"); // {"Data1", "Data2", "Data3"}
SumExpr = Expr(Sum());
for(i=1, i&amp;lt;=nitems(list), i++, 
	insert into(SumExpr, Column(dt, list[i]));
);
// see what the sumExpr looks like
show(nameexpr(sumExpr));
// then you have to do some substitute in order to actually get it to run
just_for_show = EvalExpr(
	dt &amp;lt;&amp;lt; New Column("Another Data", Formula(Expr(nameexpr(SumExpr))));
);
show(nameexpr(just_for_show));
just_for_show();// this will actually run the expression you just created. 

// or you could use the list in Sum Directly. 
// list of column names as references
list = dt &amp;lt;&amp;lt; Get Column Names();
list=list[1::3];
// can do a list directly in Sum()
// should still substitute it in so it's no dependant on then list variable
just_for_show =Substitute(
	Expr(
		dt &amp;lt;&amp;lt; new Column("Yet Another Data", Formula(Sum(DV_LIST)))
	), 
	Expr(DV_LIST), list
);

show(nameexpr(just_for_show));
just_for_show(); // actually evaluates again.  &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 08 Jun 2020 23:43:41 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Parse-a-concatenated-string-which-has-comma/m-p/271515#M52857</guid>
      <dc:creator>vince_faller</dc:creator>
      <dc:date>2020-06-08T23:43:41Z</dc:date>
    </item>
    <item>
      <title>Re: Parse a concatenated string which has comma</title>
      <link>https://community.jmp.com/t5/Discussions/Parse-a-concatenated-string-which-has-comma/m-p/271681#M52885</link>
      <description>&lt;P&gt;Thank you for helping and the explanation! The "Yet Another Data" column in your script does exactly what i want. The "Another Data" column seems to be returning an empty cell with an error "need arguments to be scalars, matrices, or lists..". I will try to figure out why this is happening.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jun 2020 19:11:13 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Parse-a-concatenated-string-which-has-comma/m-p/271681#M52885</guid>
      <dc:creator>noviJSL</dc:creator>
      <dc:date>2020-06-09T19:11:13Z</dc:date>
    </item>
  </channel>
</rss>

