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

Beginner Question about JSL

I want to save the selected rows in a csv or jmp file using JSL. But I am not able to do it Can anyone tell me how to get it done?

I tried by the following code but the way to save it appears to be wrong:

f = Function( {a},
theRows = Current Data Table() << get selected rows;
Show( theRows );

);

rs = Current Data Table() << make row state handler( f );
filepath = "C:\Users\abc\Desktop\trial";
rs << save( filepath || "\" || "part1.jmp" );
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Beginner Question about JSL

I made a mistake in the JSL I provided in my last response.  I have since then corrected my response.

In this response, I have expanded on your provided JSL, and provided a complete example that will save the subsetted table every time a new Select Rows is specified.

The row state handler is also eliminated when the Partition() window is closed.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA\semiconductor capability.jmp" );

tableCount = 0;
theRows = [];

f = Function( {a},
	// Set dupRows to the previously selected rows
	dupRows = theRows;
	// Get the current selected rows
	theRows = Current Data Table() << get selected rows;
	If( N Rows( theRows ) > 0,
		// check to see if there are the same number of rows and if yes
		// then validate the rows are different rows before saving
		If( N Rows( theRows ) == N Rows( dupRows ),
			If( Sum( dupRows == theRows ) != N Rows( theRows ),
				tableCount++;
				dtTemp = dt << subset( invisible, selected rows( 1 ), selected columns( 0 ) );
				filepath = "$TEMP";
				Close(
					dtTemp,
					save( filepath || "\" || "part" || Char( tableCount ) || ".jmp" )
				);
				Current Data Table( dt );
			);
		,
			// If not the same number of selected rows, save the subset
			tableCount++;
			Show( tableCount );
			dtTemp = dt << subset( invisible, selected rows( 1 ), selected columns( 0 ) );
			filepath = "$TEMP";
			Close( dtTemp, save( filepath || "\" || "part" || Char( tableCount ) || ".jmp" ) );
			Current Data Table( dt );
		)
	);
);

rs = Current Data Table() << make row state handler( f );

obj = Partition(
	Y( :NPN1 ),
	X( :PNP1, :PNP2, :PNP3, :PNP4, :NPN2, :NPN3, :NPN4 ),
	Method( "Decision Tree" ),
	Validation Portion( .2 )
);
obj << ShowGraph( 0 );
obj << SplitBest( 4 );
obj << Show Split Count( 1 );
obj << Show Split Prob( 1 );
Wait( .5 );

//obj << Save Predicteds;

obj << on close( Clear Symbols( rs ) );

Jim

View solution in original post

4 REPLIES 4
txnelson
Super User

Re: Beginner Question about JSL

There are many ways to handle this.  I am assuming you are going to use this JSL with the Partition() platform from your previous discussion, this is the way I would approach the solution

f = Function( {a},
	theRows = Current Data Table() << get selected rows;
	Show( theRows );

);

rs = Current Data Table() << make row state handler( f );

If( N Rows( theRows ) > 0,
	dt = Current Data Table();
	dtTemp = dt << subset( invisible, selected rows( 1 ), selected columns( 0 ) );
	filepath = "C:\Users\abc\Desktop\trial";
	Close( dtTemp, save( filepath || "\" || "part1.jmp" ) );
);

 

Jim
shasha_2
Level III

Re: Beginner Question about JSL

Yes, It is related with the Partition() platform But when I run the code to save the data, I am not able to save it. I have attached my code because I am not able to understand where the code is failing as in the log it doesn't show any error.

Georg
Level VII

Re: Beginner Question about JSL

I think you need to see the program flow, you cannot save the file befor the rows are defined.

May be this small example shows how you can handle, it saves the selected rows from partition platform in a table, when partition is closed. But as Jim mentioned: many ways!

 

Names Default To Here( 1 );
// opens partition platform on Big Class data table
// when rows are selected, and platform is closed, selected rows are saved in separate data table

dt = Open( "$SAMPLE_DATA\Big Class.jmp" );

obj = Partition( Y( :weight ), X( :sex, :height ), Method( "Decision Tree" ), Validation Portion( .2 ) );
obj << split best();

// When partition window is closed do this:
obj << on close(
	If( N Items( dt << get selected rows() ) > 0,
		dtTemp = dt << subset( invisible, selected rows( 1 ), selected columns( 0 ) );
		filepath = "$TEMP";
		Close( dttemp, save( filepath || "\" || "part1.jmp" ) );
// open file again
		Open( filepath || "\" || "part1.jmp" );
	)
);
Georg
txnelson
Super User

Re: Beginner Question about JSL

I made a mistake in the JSL I provided in my last response.  I have since then corrected my response.

In this response, I have expanded on your provided JSL, and provided a complete example that will save the subsetted table every time a new Select Rows is specified.

The row state handler is also eliminated when the Partition() window is closed.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA\semiconductor capability.jmp" );

tableCount = 0;
theRows = [];

f = Function( {a},
	// Set dupRows to the previously selected rows
	dupRows = theRows;
	// Get the current selected rows
	theRows = Current Data Table() << get selected rows;
	If( N Rows( theRows ) > 0,
		// check to see if there are the same number of rows and if yes
		// then validate the rows are different rows before saving
		If( N Rows( theRows ) == N Rows( dupRows ),
			If( Sum( dupRows == theRows ) != N Rows( theRows ),
				tableCount++;
				dtTemp = dt << subset( invisible, selected rows( 1 ), selected columns( 0 ) );
				filepath = "$TEMP";
				Close(
					dtTemp,
					save( filepath || "\" || "part" || Char( tableCount ) || ".jmp" )
				);
				Current Data Table( dt );
			);
		,
			// If not the same number of selected rows, save the subset
			tableCount++;
			Show( tableCount );
			dtTemp = dt << subset( invisible, selected rows( 1 ), selected columns( 0 ) );
			filepath = "$TEMP";
			Close( dtTemp, save( filepath || "\" || "part" || Char( tableCount ) || ".jmp" ) );
			Current Data Table( dt );
		)
	);
);

rs = Current Data Table() << make row state handler( f );

obj = Partition(
	Y( :NPN1 ),
	X( :PNP1, :PNP2, :PNP3, :PNP4, :NPN2, :NPN3, :NPN4 ),
	Method( "Decision Tree" ),
	Validation Portion( .2 )
);
obj << ShowGraph( 0 );
obj << SplitBest( 4 );
obj << Show Split Count( 1 );
obj << Show Split Prob( 1 );
Wait( .5 );

//obj << Save Predicteds;

obj << on close( Clear Symbols( rs ) );

Jim