Choose Language Hide Translation Bar
Highlighted
ZF
ZF
Level II

Re: Extract numbers of varying lengths from a string into different columns

Use Recode -Formula Column-under the New values hot spot select Advanced - Extract  Segment. Screen shots for extract d, sec,  and jmp file with saved formula for day, hour, second attached. 

Capture d.PNG

Capture_sec.PNG

View solution in original post

Highlighted
SunnyR
Level II

Re: Extract numbers of varying lengths from a string into different columns

Perfect.Thanks a lot for your description and screenshots. Saved me time in other instances by using recode.

Highlighted
Jeff_Perkinson
Community Manager Community Manager

Re: Extract numbers of varying lengths from a string into different columns

You've gotten some good solutions thus far, but I'd point out that you were really close with your use of the Words() function.

 

You can specify more than one delimiter in the last argument of the Words() function so you could do this:

 

 

vals={"0d 15h 47m 43m", "10d 10h 21m 54m","0d 04h 07m 32m", "268d 06h 02m 33m"};

for (i=1, i<=nitems(vals), i++,
	show(words(vals[i], "dhm ")) //use "d" "h" "m" and a space as delimiters
);

In the log:

 

/*:

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"};

Here it is in the formula editor, along with the In Days(), In Hours(), In Minutes() functions to convert the numeric values into the number of seconds in each of those units, to create a Duration column.

 

2020-08-01_12-05-57.466.png

I've attached the data table here as well.

 

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:

 

If you learn only one Formula Editor function, Word() is the one 

Using dates, times, datetimes and durations in JMP 

 

 

 

-Jeff