<?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: split a column and create multiple multiple based on split using JSL in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/split-a-column-and-create-multiple-multiple-based-on-split-using/m-p/345117#M59529</link>
    <description>There are advantages to both methods.  The formula method will allow for the addition of new rows and the changing of the Date values, and the c1....cn columns will automatically adjust.  The advantage of the set each value will provide static values, which can prove to be more efficient because the formulas do not have to run multiple times.</description>
    <pubDate>Fri, 01 Jan 2021 05:20:22 GMT</pubDate>
    <dc:creator>txnelson</dc:creator>
    <dc:date>2021-01-01T05:20:22Z</dc:date>
    <item>
      <title>split a column and create multiple multiple based on split using JSL</title>
      <link>https://community.jmp.com/t5/Discussions/split-a-column-and-create-multiple-multiple-based-on-split-using/m-p/345005#M59514</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to read existing table and find the column of interest [say the column name is "data"].&amp;nbsp;&lt;/P&gt;&lt;P&gt;the column "data" is numeric with "dot" delimited and have same length.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My goal is to open this table, read column "data" , remove the "dot" and create new columns [as per the length of value] and each column holds each value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Orig table:&lt;/P&gt;&lt;P&gt;data&lt;/P&gt;&lt;P&gt;------&lt;/P&gt;&lt;P&gt;123.56.8.342&lt;/P&gt;&lt;P&gt;431.02.0.567&lt;/P&gt;&lt;P&gt;318.00.1.816&lt;/P&gt;&lt;P&gt;.....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;expected output:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;data&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;c1&amp;nbsp; &amp;nbsp;c2&amp;nbsp; &amp;nbsp;c3&amp;nbsp; &amp;nbsp;c4&amp;nbsp; &amp;nbsp;c5&amp;nbsp; &amp;nbsp;c6&amp;nbsp; &amp;nbsp;c7&amp;nbsp; &amp;nbsp;c8&amp;nbsp; &amp;nbsp;c9&lt;/P&gt;&lt;P&gt;------------------------------------------------------------------------------&lt;/P&gt;&lt;P&gt;123.56.8.342&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp;6&amp;nbsp; &amp;nbsp; &amp;nbsp;8&amp;nbsp; &amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;431.02.0.567&amp;nbsp; &amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp;6&amp;nbsp; &amp;nbsp; &amp;nbsp; 7&lt;/P&gt;&lt;P&gt;318.00.1.816&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp;8&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 6&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my first attempt [trial1.jmp] , where I have 2 for loops [inner loop for creating cols, and other loop for # of rows],&amp;nbsp; it is creating more columns [ie width of the data read * no, of rows].&amp;nbsp;&lt;/P&gt;&lt;P&gt;in my second attempt [trail2.jmp], I am getting the right # of cols, but values static.&amp;nbsp;&lt;/P&gt;&lt;P&gt;attached is my jsl's.&lt;/P&gt;&lt;P&gt;Appreciate the help, burning the midnight oil on this :(&lt;/img&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:24:32 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/split-a-column-and-create-multiple-multiple-based-on-split-using/m-p/345005#M59514</guid>
      <dc:creator>david_sam</dc:creator>
      <dc:date>2023-06-10T23:24:32Z</dc:date>
    </item>
    <item>
      <title>Re: split a column and create multiple multiple based on split using JSL</title>
      <link>https://community.jmp.com/t5/Discussions/split-a-column-and-create-multiple-multiple-based-on-split-using/m-p/345065#M59519</link>
      <description>&lt;P&gt;I only checked the version 2 of .jsl and it was quite close.&lt;/P&gt;&lt;P&gt;I have attached modified version.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I modified the loop part mostly. There is most likely way to manage without Eval(Parse()) with expressions but I went with this solution this time. You were using data from variable clean_DATA which stays the same for all rows. Also if you need to have formulas you will have to use Eval(Parse()) (or expressions?) to keep formulas working in the datatable. If no formulas are needed I would go with &amp;lt;&amp;lt; Set Each Value instead of Formula.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For(i = 1, i &amp;lt;= ncols_to_add, i++, // the || operator joins two strings
	Eval(Parse("dt &amp;lt;&amp;lt; New Column(\!"c\!" || Char(i),Numeric, Continous, 
		Formula(Num(Substr(Regex(:data, \!"\D\!", \!"\!", GLOBALREPLACE ), "||char(i)||", 1 )));
	)));")); // put 1 bit in each column
);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;With &amp;lt;&amp;lt; Set Each Value the for loop would look like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;For(i = 1, i &amp;lt;= ncols_to_add, i++, // the || operator joins two strings
	dt &amp;lt;&amp;lt; New Column("c" || Char(i),Numeric, Continous, 
		&amp;lt;&amp;lt; Set Each Value(Num(Substr(Regex(:data, "\D", "", GLOBALREPLACE ), i, 1 )));
	)
); // put 1 bit in each column&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Edit:&lt;/P&gt;&lt;P&gt;Good post on using Eval Insert, Eval Expr, Parse and Substitute with formulas &lt;A href="https://community.jmp.com/t5/JSL-Cookbook/Insert-one-expression-into-another-using-Eval-Insert-Eval-Expr/ta-p/48998" target="_blank"&gt;https://community.jmp.com/t5/JSL-Cookbook/Insert-one-expression-into-another-using-Eval-Insert-Eval-Expr/ta-p/48998&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Dec 2020 08:03:55 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/split-a-column-and-create-multiple-multiple-based-on-split-using/m-p/345065#M59519</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2020-12-31T08:03:55Z</dc:date>
    </item>
    <item>
      <title>Re: split a column and create multiple multiple based on split using JSL</title>
      <link>https://community.jmp.com/t5/Discussions/split-a-column-and-create-multiple-multiple-based-on-split-using/m-p/345070#M59523</link>
      <description>&lt;P&gt;Here is how I would accomplish your request.&amp;nbsp; The Substitute() function allows for the formula to have the actual value of variable "i" to be in the formula rather than a reference to variable "i"&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );

dt = Current Data Table();

col = Column( dt, "DATA" );

colLength = Length( col[1] );

For( i = 1, i &amp;lt;= colLength, i++,
	If( Substr( col[1], i, 1 ) != ".",
		Eval(
			Substitute(
					Expr(
						dt &amp;lt;&amp;lt; New Column( "c" || Char( i ), Numeric, Continous, Formula( Num( Substr( :data, __i__, 1 ) ) ) )
					),
				Expr( __i__ ), i,

			)
		)
	)
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Dec 2020 12:31:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/split-a-column-and-create-multiple-multiple-based-on-split-using/m-p/345070#M59523</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-12-31T12:31:20Z</dc:date>
    </item>
    <item>
      <title>Re: split a column and create multiple multiple based on split using JSL</title>
      <link>https://community.jmp.com/t5/Discussions/split-a-column-and-create-multiple-multiple-based-on-split-using/m-p/345092#M59527</link>
      <description>&lt;P&gt;Thank Jamo for letting me know what I was missing. I knew I was close ;)&lt;/img&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dint know about about "set each value" built in function.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;yup, everything works !&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jan 2021 00:04:11 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/split-a-column-and-create-multiple-multiple-based-on-split-using/m-p/345092#M59527</guid>
      <dc:creator>david_sam</dc:creator>
      <dc:date>2021-01-01T00:04:11Z</dc:date>
    </item>
    <item>
      <title>Re: split a column and create multiple multiple based on split using JSL</title>
      <link>https://community.jmp.com/t5/Discussions/split-a-column-and-create-multiple-multiple-based-on-split-using/m-p/345093#M59528</link>
      <description>&lt;P&gt;Thanks Jim.&amp;nbsp;&lt;/P&gt;&lt;P&gt;you have&amp;nbsp; elegant solution.&amp;nbsp;&lt;/P&gt;&lt;P&gt;based on your proposed method, I noticed see the col name are not continues, [ie. skips the Col # when ever "dot" is encountered]; little column names massaging is needed [which I took care].&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Question:&lt;/P&gt;&lt;P&gt;Would you suggest to have column have formula and use eval/substitute or do it with "set each value" as Jamo suggested from the performance standpoint?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;</description>
      <pubDate>Fri, 01 Jan 2021 00:12:02 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/split-a-column-and-create-multiple-multiple-based-on-split-using/m-p/345093#M59528</guid>
      <dc:creator>david_sam</dc:creator>
      <dc:date>2021-01-01T00:12:02Z</dc:date>
    </item>
    <item>
      <title>Re: split a column and create multiple multiple based on split using JSL</title>
      <link>https://community.jmp.com/t5/Discussions/split-a-column-and-create-multiple-multiple-based-on-split-using/m-p/345117#M59529</link>
      <description>There are advantages to both methods.  The formula method will allow for the addition of new rows and the changing of the Date values, and the c1....cn columns will automatically adjust.  The advantage of the set each value will provide static values, which can prove to be more efficient because the formulas do not have to run multiple times.</description>
      <pubDate>Fri, 01 Jan 2021 05:20:22 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/split-a-column-and-create-multiple-multiple-based-on-split-using/m-p/345117#M59529</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2021-01-01T05:20:22Z</dc:date>
    </item>
  </channel>
</rss>

