<?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: Extract numbers of varying lengths from a string into different columns in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Extract-numbers-of-varying-lengths-from-a-string-into-different/m-p/283327#M54801</link>
    <description>&lt;P&gt;Perfect.Thanks a lot for your description and screenshots. Saved me time in other instances by using recode.&lt;/P&gt;</description>
    <pubDate>Fri, 31 Jul 2020 21:50:45 GMT</pubDate>
    <dc:creator>SunnyR</dc:creator>
    <dc:date>2020-07-31T21:50:45Z</dc:date>
    <item>
      <title>Extract numbers of varying lengths from a string into different columns</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-numbers-of-varying-lengths-from-a-string-into-different/m-p/282544#M54676</link>
      <description>&lt;P&gt;I have&amp;nbsp; a column named Duration with values which represent number of days,hours, min and sec. The last m denotes seconds.&lt;/P&gt;&lt;P&gt;So the typical format would be : (0-365)d(0-24)h(0-60)m(0-60)m&lt;/P&gt;&lt;P&gt;Here are some examples.:&lt;/P&gt;&lt;P&gt;0d 15h 47m 43m&lt;/P&gt;&lt;P&gt;10d 10h 21m 54m&lt;/P&gt;&lt;P&gt;0d 04h 07m 32m&lt;/P&gt;&lt;P&gt;268d 06h 02m 33m&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to extract the number of days, Hours,minutes, and sec in different columns so that I can perform calculations on it.&lt;/P&gt;&lt;P&gt;I tried the formula for extracting the number of days,&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt; Words( :Duration, "d" )[1] &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For extracting the the second number - I used the formula :&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Substr( Item( 2, :Duration ), 1, 2 );&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In the same way extracted the third and fourth number using 3 and 4 in the Item formula.&lt;/P&gt;&lt;P&gt;To convert these strings to numeric, I created 4 more columns;copied and pasted and changed the data type to numeric.&lt;/P&gt;&lt;P&gt;I understand this is a round about way to get to the result.&lt;/P&gt;&lt;P&gt;I was wondering if anyone could help me with a more efficient way.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Jun 2023 23:16:57 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-numbers-of-varying-lengths-from-a-string-into-different/m-p/282544#M54676</guid>
      <dc:creator>SunnyR</dc:creator>
      <dc:date>2023-06-10T23:16:57Z</dc:date>
    </item>
    <item>
      <title>Re: Extract numbers of varying lengths from a string into different columns</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-numbers-of-varying-lengths-from-a-string-into-different/m-p/282547#M54677</link>
      <description>&lt;P&gt;How about using Regex:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the Day:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Num( Regex( :Duration, "(\d+)d\s(\d+)h\s(\d+)m\s(\d+)m", "\1" ) )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For the Hour:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Num( Regex( :Duration, "(\d+)d\s(\d+)h\s(\d+)m\s(\d+)m", "\2" ) )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For the Minute:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Num( Regex( :Duration, "(\d+)d\s(\d+)h\s(\d+)m\s(\d+)m", "\3" ) )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For the Second:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Num( Regex( :Duration, "(\d+)d\s(\d+)h\s(\d+)m\s(\d+)m", "\4" ) )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Each number is in a capturing group although you really don't need to capture the others. You could simplify it with these:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Num( Regex( :Duration, "(\d+)d\s\d+h\s\d+m\s\d+m", "\1" ) )
Num( Regex( :Duration, "\d+d\s(\d+)h\s\d+m\s\d+m", "\1" ) )
Num( Regex( :Duration, "\d+d\s\d+h\s(\d+)m\s\d+m", "\1" ) )
Num( Regex( :Duration, "\d+d\s\d+h\s\d+m\s(\d+)m", "\1" ) )&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2020 19:40:13 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-numbers-of-varying-lengths-from-a-string-into-different/m-p/282547#M54677</guid>
      <dc:creator>paul_vezzetti</dc:creator>
      <dc:date>2020-07-28T19:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: Extract numbers of varying lengths from a string into different columns</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-numbers-of-varying-lengths-from-a-string-into-different/m-p/282552#M54678</link>
      <description>&lt;P&gt;Attached sample table.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jul 2020 19:47:15 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-numbers-of-varying-lengths-from-a-string-into-different/m-p/282552#M54678</guid>
      <dc:creator>paul_vezzetti</dc:creator>
      <dc:date>2020-07-28T19:47:15Z</dc:date>
    </item>
    <item>
      <title>Re: Extract numbers of varying lengths from a string into different columns</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-numbers-of-varying-lengths-from-a-string-into-different/m-p/282556#M54679</link>
      <description>&lt;P&gt;This example illustrates how to use regular expressions.&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 );

cell = {"0d 15h 47m 43m", "10d 10h 21m 54m", "0d 04h 07m 32m", "268d 06h 02m 33m"};

For( i = 1, i &amp;lt;= N Items( cell ), i++,
	day = Num( Regex( cell[i], "(\d+)d (\d+)h (\d+)m (\d+)m", "\1" ) );
	Show( day );
);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Jul 2020 19:52:09 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-numbers-of-varying-lengths-from-a-string-into-different/m-p/282556#M54679</guid>
      <dc:creator>Mark_Bailey</dc:creator>
      <dc:date>2020-07-28T19:52:09Z</dc:date>
    </item>
    <item>
      <title>Re: Extract numbers of varying lengths from a string into different columns</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-numbers-of-varying-lengths-from-a-string-into-different/m-p/282955#M54739</link>
      <description>&lt;P&gt;Use Recode -Formula Column-under the New values hot spot select Advanced - Extract&amp;nbsp; Segment. Screen shots for extract d, sec,&amp;nbsp; and jmp file with saved formula for day, hour, second attached.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture d.PNG" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/25913i7BFCCB43DF43F683/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture d.PNG" alt="Capture d.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture_sec.PNG" style="width: 400px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/25914iB0F2602EEBE586CF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture_sec.PNG" alt="Capture_sec.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Sat, 01 Aug 2020 16:12:34 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-numbers-of-varying-lengths-from-a-string-into-different/m-p/282955#M54739</guid>
      <dc:creator>ZF</dc:creator>
      <dc:date>2020-08-01T16:12:34Z</dc:date>
    </item>
    <item>
      <title>Re: Extract numbers of varying lengths from a string into different columns</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-numbers-of-varying-lengths-from-a-string-into-different/m-p/283327#M54801</link>
      <description>&lt;P&gt;Perfect.Thanks a lot for your description and screenshots. Saved me time in other instances by using recode.&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jul 2020 21:50:45 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-numbers-of-varying-lengths-from-a-string-into-different/m-p/283327#M54801</guid>
      <dc:creator>SunnyR</dc:creator>
      <dc:date>2020-07-31T21:50:45Z</dc:date>
    </item>
    <item>
      <title>Re: Extract numbers of varying lengths from a string into different columns</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-numbers-of-varying-lengths-from-a-string-into-different/m-p/283334#M54802</link>
      <description>&lt;P&gt;Paul- I learnt a new function. Thanks a lot for your detailed and simplified version of the solution.!&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jul 2020 23:51:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-numbers-of-varying-lengths-from-a-string-into-different/m-p/283334#M54802</guid>
      <dc:creator>SunnyR</dc:creator>
      <dc:date>2020-07-31T23:51:24Z</dc:date>
    </item>
    <item>
      <title>Re: Extract numbers of varying lengths from a string into different columns</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-numbers-of-varying-lengths-from-a-string-into-different/m-p/283660#M54805</link>
      <description>&lt;P&gt;You've gotten some good solutions thus far, but I'd point out that you were really close with your use of the &lt;A href="https://www.jmp.com/support/help/en/15.2/#page/jmp/character-functions.shtml#ww176288" target="_self"&gt;Words()&lt;/A&gt; function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can specify more than one delimiter in the last argument of the Words() function so you could do this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;vals={"0d 15h 47m 43m", "10d 10h 21m 54m","0d 04h 07m 32m", "268d 06h 02m 33m"};

for (i=1, i&amp;lt;=nitems(vals), i++,
	show(words(vals[i], "dhm ")) //use "d" "h" "m" and a space as delimiters
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In the log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;/*:

Words(vals[i], "dhm ") = {"0", "15", "47", "43"};
Words(vals[i], "dhm ") = {"10", "10", "21", "54"};
Words(vals[i], "dhm ") = {"0", "04", "07", "32"};
Words(vals[i], "dhm ") = {"268", "06", "02", "33"};
&lt;/PRE&gt;
&lt;P&gt;Here it is in the formula editor, along with the &lt;A href="https://www.jmp.com/support/help/en/15.2/#page/jmp/date-time-functions.shtml#ww123215" target="_self"&gt;In Days(), In Hours(), In Minutes() functions&lt;/A&gt; to convert the numeric values into the number of seconds in each of those units, to create a Duration column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2020-08-01_12-05-57.466.png" style="width: 633px;"&gt;&lt;img src="https://community.jmp.com/t5/image/serverpage/image-id/25912i1BF8DDAF3E03BEAF/image-dimensions/633x337?v=v2" width="633" height="337" role="button" title="2020-08-01_12-05-57.466.png" alt="2020-08-01_12-05-57.466.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I've attached the data table here as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This topic combines two of my favorite features, the Word() (or Words()) function and dates and times. Here are posts I wrote explaining each of them:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;LI-MESSAGE title="If you learn only one Formula Editor function, Word() is the one" uid="30381" url="https://community.jmp.com/t5/JMP-Blog/If-you-learn-only-one-Formula-Editor-function-Word-is-the-one/m-p/30381#U30381" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-blog-thread lia-fa-icon lia-fa-blog lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;LI-MESSAGE title="Using dates, times, datetimes and durations in JMP" uid="68689" url="https://community.jmp.com/t5/JMPer-Cable/Using-dates-times-datetimes-and-durations-in-JMP/m-p/68689#U68689" discussion_style_icon_css="lia-mention-container-editor-message lia-img-icon-blog-thread lia-fa-icon lia-fa-blog lia-fa-thread lia-fa"&gt;&lt;/LI-MESSAGE&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 01 Aug 2020 16:11:08 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-numbers-of-varying-lengths-from-a-string-into-different/m-p/283660#M54805</guid>
      <dc:creator>Jeff_Perkinson</dc:creator>
      <dc:date>2020-08-01T16:11:08Z</dc:date>
    </item>
    <item>
      <title>Re: Extract numbers of varying lengths from a string into different columns</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-numbers-of-varying-lengths-from-a-string-into-different/m-p/284543#M54962</link>
      <description>&lt;P&gt;Mark,&lt;/P&gt;&lt;P&gt;&amp;nbsp; I tried using your script in many different ways&amp;nbsp;&lt;/P&gt;&lt;P&gt;a) by using the script in the script editor and running it,&lt;/P&gt;&lt;P&gt;b) creating a column with name "cell" and entering the list of items in it + creating another column "day" and using the "for loop" as a formula in that column,&lt;/P&gt;&lt;P&gt;and other ways.&lt;/P&gt;&lt;P&gt;I get an error.&lt;/P&gt;&lt;P&gt;I tried looking around in the scripting index for help too.&lt;/P&gt;&lt;P&gt;&amp;nbsp;But I cannot get the script to work.&amp;nbsp; I am new to scripting. Can you please help.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Aug 2020 18:17:53 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-numbers-of-varying-lengths-from-a-string-into-different/m-p/284543#M54962</guid>
      <dc:creator>SunnyR</dc:creator>
      <dc:date>2020-08-06T18:17:53Z</dc:date>
    </item>
    <item>
      <title>Re: Extract numbers of varying lengths from a string into different columns</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-numbers-of-varying-lengths-from-a-string-into-different/m-p/284646#M54982</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/5358"&gt;@Mark_Bailey&lt;/a&gt;&amp;nbsp;script is a standalone JSL.&amp;nbsp; You run it by putting it into a script window and running the script.&amp;nbsp; I did that and it worked great, giving the following results in the JMP log&lt;/P&gt;
&lt;PRE&gt;day = 0;
day = 10;
day = 0;
day = 268;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Aug 2020 23:40:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-numbers-of-varying-lengths-from-a-string-into-different/m-p/284646#M54982</guid>
      <dc:creator>txnelson</dc:creator>
      <dc:date>2020-08-06T23:40:59Z</dc:date>
    </item>
    <item>
      <title>Re: Extract numbers of varying lengths from a string into different columns</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-numbers-of-varying-lengths-from-a-string-into-different/m-p/284750#M54998</link>
      <description>&lt;P&gt;&lt;a href="https://community.jmp.com/t5/user/viewprofilepage/user-id/2687"&gt;@txnelson&lt;/a&gt;&amp;nbsp;is correct. He showed you how to use it as a separate script. This expression is all that you need for a column formula:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Num( Regex( cell[i], "(\d+)d (\d+)h (\d+)m (\d+)m", "\1" ) )&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Aug 2020 16:19:34 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-numbers-of-varying-lengths-from-a-string-into-different/m-p/284750#M54998</guid>
      <dc:creator>Mark_Bailey</dc:creator>
      <dc:date>2020-08-07T16:19:34Z</dc:date>
    </item>
    <item>
      <title>Re: Extract numbers of varying lengths from a string into different columns</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-numbers-of-varying-lengths-from-a-string-into-different/m-p/284752#M54999</link>
      <description>&lt;P&gt;Mark&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I was under the impression that the result will show up in a separate window. Now, I looked into the log- and I saw the result there,- as many times I had run the script.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Aug 2020 16:32:18 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-numbers-of-varying-lengths-from-a-string-into-different/m-p/284752#M54999</guid>
      <dc:creator>SunnyR</dc:creator>
      <dc:date>2020-08-07T16:32:18Z</dc:date>
    </item>
    <item>
      <title>Re: Extract numbers of varying lengths from a string into different columns</title>
      <link>https://community.jmp.com/t5/Discussions/Extract-numbers-of-varying-lengths-from-a-string-into-different/m-p/284753#M55000</link>
      <description>&lt;P&gt;Thanks a lot for pointing me to the log. I saw the result there.Previously I was thinking that the result will show up in a separate window.&lt;/P&gt;</description>
      <pubDate>Fri, 07 Aug 2020 16:34:46 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Extract-numbers-of-varying-lengths-from-a-string-into-different/m-p/284753#M55000</guid>
      <dc:creator>SunnyR</dc:creator>
      <dc:date>2020-08-07T16:34:46Z</dc:date>
    </item>
  </channel>
</rss>

