<?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 Column Based on Text in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Split-Column-Based-on-Text/m-p/319449#M56991</link>
    <description>&lt;P&gt;This is so awesome, thank you &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;&amp;nbsp;!&amp;nbsp;This code is going to greatly reduce the time it takes me to clean my data, I greatly appreciate your response. Quick question: Is there a way to embed the new variables directly into the existing dt rather than creating a new one and then merging back to the original dt?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Stephanie&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 08 Oct 2020 22:34:49 GMT</pubDate>
    <dc:creator>sagrim</dc:creator>
    <dc:date>2020-10-08T22:34:49Z</dc:date>
    <item>
      <title>Split Column Based on Text</title>
      <link>https://community.jmp.com/t5/Discussions/Split-Column-Based-on-Text/m-p/319318#M56982</link>
      <description>&lt;P&gt;Good afternoon.&amp;nbsp; I am attempting to split one column into three new columns and place a piece of the string from the original column into one of the three new columns &lt;U&gt;based on the context of the text.&lt;/U&gt;&amp;nbsp; I understand that text to columns would parse out the string based on some delimiter, however, this doesn’t quite get me where I need to be.&amp;nbsp; I need a function that reads the text, checks for certain keywords (years, months or days) and then places a piece of the string (the numerical value that precedes “years”, “months” or “days”) in the appropriate column. &amp;nbsp;I see that the word() function can extrapolate the first word or value and this would be a start but then the value still needs to be placed in one of three potential columns based on the text. Does anyone have thoughts on how to code this?&amp;nbsp; Or ideas for a potential work-around?&amp;nbsp; Any insight is greatly appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example attached where column 1 shows the data in its current format and columns 2-4 are the ideal state.&amp;nbsp; Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Stephanie&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 23:40:07 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Split-Column-Based-on-Text/m-p/319318#M56982</guid>
      <dc:creator>sagrim</dc:creator>
      <dc:date>2023-06-09T23:40:07Z</dc:date>
    </item>
    <item>
      <title>Re: Split Column Based on Text</title>
      <link>https://community.jmp.com/t5/Discussions/Split-Column-Based-on-Text/m-p/319423#M56986</link>
      <description>&lt;P&gt;Here is one way to handle this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
dt = New Table( "Example dt",
	Add Rows( 10 ),
	Set Header Height( 46 ),
	New Column( "Age",
		Character,
		"Nominal",
		Set Selected,
		Set Values(
			{"2-day old", "43-day old", "3-day old",
			"3-month old", "4-month old", "5-day old",
			"32-day old", "13-year old", "10-year old",
			"10-month old"}
		)
	)
);
dt &amp;lt;&amp;lt; New Column( "AgeYears" );
dt &amp;lt;&amp;lt; New Column( "AgeMonths" );
dt &amp;lt;&amp;lt; New Column( "AgeDays" );

For( i = 1, i &amp;lt;= N Rows( dt ), i++,
	Match( Word( 2, :Age[i], "- " ),
		"day",
			:AgeDays[i] =
			Num( Word( 1, :age[i], "- " ) ),
		"month",
			:AgeMonths[i] =
			Num( Word( 1, :age[i], "- " ) ),
		"year",
			:AgeYears[i] =
			Num( Word( 1, :age[i], "- " ) )
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Above was corrected as noted.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Oct 2020 20:50:52 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Split-Column-Based-on-Text/m-p/319423#M56986</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-10-08T20:50:52Z</dc:date>
    </item>
    <item>
      <title>Re: Split Column Based on Text</title>
      <link>https://community.jmp.com/t5/Discussions/Split-Column-Based-on-Text/m-p/319424#M56987</link>
      <description>Hi,&lt;BR /&gt;I think there is a minor typo at the end of the script: in the last Match case, the receiving column should be :AgeYears[i], not :AgeMonths[i].&lt;BR /&gt;Best,&lt;BR /&gt;TS</description>
      <pubDate>Thu, 08 Oct 2020 20:47:37 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Split-Column-Based-on-Text/m-p/319424#M56987</guid>
      <dc:creator>Thierry_S</dc:creator>
      <dc:date>2020-10-08T20:47:37Z</dc:date>
    </item>
    <item>
      <title>Re: Split Column Based on Text</title>
      <link>https://community.jmp.com/t5/Discussions/Split-Column-Based-on-Text/m-p/319449#M56991</link>
      <description>&lt;P&gt;This is so awesome, thank you &lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;&amp;nbsp;!&amp;nbsp;This code is going to greatly reduce the time it takes me to clean my data, I greatly appreciate your response. Quick question: Is there a way to embed the new variables directly into the existing dt rather than creating a new one and then merging back to the original dt?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Stephanie&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Oct 2020 22:34:49 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Split-Column-Based-on-Text/m-p/319449#M56991</guid>
      <dc:creator>sagrim</dc:creator>
      <dc:date>2020-10-08T22:34:49Z</dc:date>
    </item>
    <item>
      <title>Re: Split Column Based on Text</title>
      <link>https://community.jmp.com/t5/Discussions/Split-Column-Based-on-Text/m-p/319450#M56992</link>
      <description>&lt;P&gt;Good catch&amp;nbsp;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/11634"&gt;@Thierry_S&lt;/a&gt;&amp;nbsp;.&amp;nbsp; Thank you !&lt;/P&gt;</description>
      <pubDate>Thu, 08 Oct 2020 22:35:54 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Split-Column-Based-on-Text/m-p/319450#M56992</guid>
      <dc:creator>sagrim</dc:creator>
      <dc:date>2020-10-08T22:35:54Z</dc:date>
    </item>
    <item>
      <title>Re: Split Column Based on Text</title>
      <link>https://community.jmp.com/t5/Discussions/Split-Column-Based-on-Text/m-p/319454#M56993</link>
      <description>&lt;P&gt;I don't know what you are asking.&amp;nbsp; My example has one data table, which is then acted on to give you 3 new columns, in the original data table.&amp;nbsp; Isn't that what you are asking for?&amp;nbsp; If you just want the new columns created directly into an already existing data table, the JSL would be&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default to Here( 1 );
dt = Current Data Table();
// or dt = Data Table("your data table's name");

dt &amp;lt;&amp;lt; New Column( "AgeYears" );
dt &amp;lt;&amp;lt; New Column( "AgeMonths" );
dt &amp;lt;&amp;lt; New Column( "AgeDays" );

For( i = 1, i &amp;lt;= N Rows( dt ), i++,
	Match( Word( 2, :Age[i], "- " ),
		"day",
			:AgeDays[i] =
			Num( Word( 1, :age[i], "- " ) ),
		"month",
			:AgeMonths[i] =
			Num( Word( 1, :age[i], "- " ) ),
		"year",
			:AgeYears[i] =
			Num( Word( 1, :age[i], "- " ) )
	)
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It appears that you need to do some reading.&amp;nbsp; If you are new to JMP you need to read the Discovering JMP and Using JMP documents.&amp;nbsp; One really needs to know what is available in JMP for one to become a JSL scripter.&amp;nbsp; And also, after reading those 2 documents, you need to read the Scripting Guide.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Oct 2020 00:47:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Split-Column-Based-on-Text/m-p/319454#M56993</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-10-09T00:47:42Z</dc:date>
    </item>
  </channel>
</rss>

