cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
JMP2021
Level III

How to split a 500-character long string into 500 columns, one char per column?

Is there a simple way to split a column containing 500-character long string into 500 columns, one char per column?

I am using JMP17.

 

JMP2021_0-1691175815948.png

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User

Re: How to split a 500-character long string into 500 columns, one char per column?

Here is a little different approach to the problem.  It uses some built in JMP functions that might prove to be faster than @Jackie_ approach.

Names Default To Here( 1 );
dt = Current Data Table();
// Create a new column that has a delimiter between each character
dt << New Column( "Char",
	character,
	set each value(
		x = Words( As Column( 1 ), "" );
		Concat Items( x, "`" );
	)
);
// Use Text to Columns to create the new columns and populate them
dt << text to columns( columns( char ), delimiters( "`" ) );
// Cleanup the table
dt << delete columns( char );
Jim

View solution in original post

ron_horne
Super User (Alumni)

Re: How to split a 500-character long string into 500 columns, one char per column?

All the answers you got so far were good. but there is another non scripting option.


yet, the text to cols add in works just fine
https://community.jmp.com/t5/JMP-Add-Ins/Text-to-Columns-Version-3/ta-p/21621
just leave the delimiter empty and it will split each letter into a new column with just 3 clicks.

 

for some reason, using the built in text to columns from the cols >> utilities >> text to columns... will not work without a separator

View solution in original post

9 REPLIES 9
Jackie_
Level VI

Re: How to split a 500-character long string into 500 columns, one char per column?

Try something like this 

 


dt = Current Data Table();

dt << Begin data update;
For( j = 1, j <= N Rows( dt ), j++, 

	For( i = 1, i <= 500, i++, //you might want to use length of the string than 500
	
	
		dt << New Column( Word( i, Column( dt, 1 )[j], "" ) )
	)
);
dt << End data update;
JMP2021
Level III

Re: How to split a 500-character long string into 500 columns, one char per column?

My JMP is not responding when I try your scripts. IT probably because that my table is large. I guess it will work for a smaller table.

JMP2021
Level III

Re: How to split a 500-character long string into 500 columns, one char per column?

JMP2021_0-1691180153232.png

 

txnelson
Super User

Re: How to split a 500-character long string into 500 columns, one char per column?

Here is a little different approach to the problem.  It uses some built in JMP functions that might prove to be faster than @Jackie_ approach.

Names Default To Here( 1 );
dt = Current Data Table();
// Create a new column that has a delimiter between each character
dt << New Column( "Char",
	character,
	set each value(
		x = Words( As Column( 1 ), "" );
		Concat Items( x, "`" );
	)
);
// Use Text to Columns to create the new columns and populate them
dt << text to columns( columns( char ), delimiters( "`" ) );
// Cleanup the table
dt << delete columns( char );
Jim
JMP2021
Level III

Re: How to split a 500-character long string into 500 columns, one char per column?

I am new to scripting. Is there a way to specify which column to perform this split char?

RIght now I delete all the other columns and only leave the one column that contains the long string. IT worked wonderfully.

 

 

JMP2021
Level III

Re: How to split a 500-character long string into 500 columns, one char per column?

never mind. I only need to put that column as the 1st column in a table. Thank you very much for your help

txnelson
Super User

Re: How to split a 500-character long string into 500 columns, one char per column?

In the JSL I provided, the column to use to separate into multiple columns is referenced as

As Column( 1 )

This specifies for the Words() function to use the first column in the data table to do the separation of characters on.  The numeric value can be changed to point to whatever column number one wants.  The column number can also be changed to the actual column name.  

as column( "the column name" )
Jim
ron_horne
Super User (Alumni)

Re: How to split a 500-character long string into 500 columns, one char per column?

All the answers you got so far were good. but there is another non scripting option.


yet, the text to cols add in works just fine
https://community.jmp.com/t5/JMP-Add-Ins/Text-to-Columns-Version-3/ta-p/21621
just leave the delimiter empty and it will split each letter into a new column with just 3 clicks.

 

for some reason, using the built in text to columns from the cols >> utilities >> text to columns... will not work without a separator

JMP2021
Level III

Re: How to split a 500-character long string into 500 columns, one char per column?

Thank you so much. This is so easy to use. wonderful trick to know!