cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
ducthinh279
Level II

How can I parse a string in 1 column use jsl?

I want to use jsl to split data in column "result" with delimiter "|" to new column "PIN" and "value". Kindly help, thank you in advance

Please refer my attachment

ducthinh279_0-1711611548608.png

new table

ducthinh279_1-1711611572700.png

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User

Re: How can I parse a string in 1 column use jsl?

Given the data table

txnelson_0-1711614464639.png

This JSL will produce the required new table

names default to here(1);

// Create a handle to point to the data table in question
dt = current data table();

// Convert the Result column into several columns
// Text to columns
dt << Text to Columns(
	columns( :Result ),
	Delimiters( "|" )
);

// Use a multiple series stack to stack the data
dtStack = dt << Stack(
	columns( :Result 2, :Result 3, :Result 4, :Result 5, :Result 6, :Result 7 ),
	Source Label Column( "Label" ),
	Stacked Data Column( "Data" ),
	"Non-stacked columns"n( Keep( :Unit#, :Result 1 ) ),
	Number of Series( 2 ),
	Output Table( "Untitled 20.jmp" )
);

// Delete unneeded columns
dtStack << delete columns(:Label,:Label2);

// Rename the stacked columns
dtStack:Result 1 << set name ("Number Of Tests");
dtStack:Data << set name("PIN");
dtStack:Data2 << set name("Value");

txnelson_1-1711614564309.png

All of the above JSL was created by running the Text to Columns, Stack and Column name changes etc. interactively, and then going to the JMP log and cutting and pasting the JSL that JMP produced into a script window.  I will confess to some cleaning up of cut and pasted JSL to make it look better.

 

Jim

View solution in original post

txnelson
Super User

Re: How can I parse a string in 1 column use jsl?

  1. Replace the Stack code with this
    // Get all of the column names
    resultList = dt << get column names();
    // Only the columns Result 2 thru Result N are to be 
    // stacked, so remove the first 3 columns from the list
    remove from(resultList,1,3);
    
    // Use a multiple series stack to stack the data
    dtStack = dt << Stack(
    	columns( resultList ),
    	Source Label Column( "Label" ),
    	Stacked Data Column( "Data" ),
    	"Non-stacked columns"n( Keep( :Unit#, :Result 1 ) ),
    	Number of Series( 2 ),
    	Output Table( "Untitled 20.jmp" )
    );

     

  2. Take the time to read the Scripting Guide available in the JMP Documentation Library available under the Help pull down menu.
Jim

View solution in original post

7 REPLIES 7
jthi
Super User

Re: How can I parse a string in 1 column use jsl?

Split a Data Table Column into Multiple Columns (jmp.com)

Select your column

jthi_0-1711614053824.png

go to columns menu

jthi_1-1711614068239.png

set your delimilter

jthi_2-1711614082949.png

press OK and you have your result

jthi_3-1711614099017.png

copy script from enhanced log / workflow and modify it as needed

// Text to columns
Data Table("Sheet1") << Text to Columns(columns(:Result), Delimiters("|"));
-Jarmo
ducthinh279
Level II

Re: How can I parse a string in 1 column use jsl?

thank you a lot

txnelson
Super User

Re: How can I parse a string in 1 column use jsl?

Given the data table

txnelson_0-1711614464639.png

This JSL will produce the required new table

names default to here(1);

// Create a handle to point to the data table in question
dt = current data table();

// Convert the Result column into several columns
// Text to columns
dt << Text to Columns(
	columns( :Result ),
	Delimiters( "|" )
);

// Use a multiple series stack to stack the data
dtStack = dt << Stack(
	columns( :Result 2, :Result 3, :Result 4, :Result 5, :Result 6, :Result 7 ),
	Source Label Column( "Label" ),
	Stacked Data Column( "Data" ),
	"Non-stacked columns"n( Keep( :Unit#, :Result 1 ) ),
	Number of Series( 2 ),
	Output Table( "Untitled 20.jmp" )
);

// Delete unneeded columns
dtStack << delete columns(:Label,:Label2);

// Rename the stacked columns
dtStack:Result 1 << set name ("Number Of Tests");
dtStack:Data << set name("PIN");
dtStack:Data2 << set name("Value");

txnelson_1-1711614564309.png

All of the above JSL was created by running the Text to Columns, Stack and Column name changes etc. interactively, and then going to the JMP log and cutting and pasting the JSL that JMP produced into a script window.  I will confess to some cleaning up of cut and pasted JSL to make it look better.

 

Jim
ducthinh279
Level II

Re: How can I parse a string in 1 column use jsl?

thanks Jim so much, it is very good solution

ducthinh279
Level II

Re: How can I parse a string in 1 column use jsl?

// Use a multiple series stack to stack the data
dtStack = dt << Stack(
	columns( :Result 2, :Result 3, :Result 4, :Result 5, :Result 6, :Result 7 ),

in the step above, If my dataset return so many result up to result 120, and it variance may be more than 120 result, do we have any way to code jsl script to stack data Jim?

txnelson
Super User

Re: How can I parse a string in 1 column use jsl?

  1. Replace the Stack code with this
    // Get all of the column names
    resultList = dt << get column names();
    // Only the columns Result 2 thru Result N are to be 
    // stacked, so remove the first 3 columns from the list
    remove from(resultList,1,3);
    
    // Use a multiple series stack to stack the data
    dtStack = dt << Stack(
    	columns( resultList ),
    	Source Label Column( "Label" ),
    	Stacked Data Column( "Data" ),
    	"Non-stacked columns"n( Keep( :Unit#, :Result 1 ) ),
    	Number of Series( 2 ),
    	Output Table( "Untitled 20.jmp" )
    );

     

  2. Take the time to read the Scripting Guide available in the JMP Documentation Library available under the Help pull down menu.
Jim
ducthinh279
Level II

Re: How can I parse a string in 1 column use jsl?

it so great, I have just went to JMP Documentation Library, I can find the guide. thank you a lot.