Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
OneNorthJMP
Level IV

Stack Multiple Parameter with condition with JSL

I got a dataset with multiple parameters with certain format "TestNumber;TestName". I know we can easily to it manually. But 

I want to stack them all with JSL in a smart way. How to do this in JSL ? Please advise. Thanks 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
pmroz
Super User

Re: Stack Multiple Parameter with condition with JSL

You needed to convert the column names to a string.  Also one_col is not a list.  Here's the corrected code.  I encourage you to 

a) Read the scripting manuals

b) Check the log frequently for variable values, error messages etc.

c) Keep using this discussion forum

 

Names Default To Here( 1 );

sourceTable = Data Table( "FINAL" );

col_list = sourceTable << get column names( continuous, string );
stackcols = {};
//one_col = {};

For( i = 1, i <= N Items( col_list ), i++,
	one_col = col_list[i];
	show(one_col, i);
	If( Regex( one_col, "(\d+);(\S+)" ) == one_col,
		Insert Into( stackcols, one_col )
	);
);

resultTable = sourceTable << Stack(
	columns( stackcols ),
	Source Label Column( "Label" ),
	Stacked Data Column( "Data" )
);
resultTable << setName( (sourceTable << getName) || " Stacked Data" );

View solution in original post

10 REPLIES 10
Highlighted
ian_jmp
Staff

Re: Stack Multiple Parameter with condition with JSL

If you can, it's a good idea to let JMP do the work for you - Generally you only need to do things 'by hand' once, then use the code that JMP generates automatically.

 

In you case, if you do 'Tables > Stack':

Screen Shot 2019-08-29 at 10.02.00.png

hitting 'OK' gives a new table that has a saved script called 'Source'. If you right-click on the associated green 'run' icon, you can select 'Edit', which will give you this script:

Data Table( "FINAL.jmp" ) << Stack(
	columns(
		:Name( "2010;PinShort@CLK" ),
		:Name( "2011;PinShort@IO" ),
		:Name( "2012;PinShort@VDD" ),
		:Name( "2013;PinShort@LA" ),
		:Name( "2014;PinShort@LB" ),
		:Name( "2030;PinOpen@CLK" ),
		:Name( "2031;PinOpen@IO" ),
		:Name( "2032;PinOpen@VDD" ),
		:Name( "2033;PinOpen@LA" ),
		:Name( "2034;PinOpen@LB" ),
		:Name( "2200;Ana_Idd_noClock@VDD" ),
		:Name( "2360;Dig_ATE_FUN_00_001_Authenticate" ),
		:Name( "2361;Dig_ATE_FUN_00_003_DisableReset" ),
		:Name( "2380;Dig_ATE_FUN_00_004_GetVersion" ),
		:Name( "2440;SyncPulse_and_capResponse_0x90" ),
		:Name( "2441;Ana_Pads_ATE_VOL_0uA@IO" ),
		:Name( "2442;Ana_Pads_ATE_VOH_0uA@IO" ),
		:Name( "2443;Ana_Pads_ATE_VOL_0uA_IDD@VDD" ),
		:Name( "2444;Ana_Pads_ATE_VOL_0uA_Rcont_GND@VSS" )
	),
	Source Label Column( "Label" ),
	Stacked Data Column( "Data" )
)

You can make this script smarter, but if you are just adding new rows it will work fine (so long as the columns it needs are still in the source table).

Highlighted
OneNorthJMP
Level IV

Re: Stack Multiple Parameter with condition with JSL

Hi Ian,

I know this already. The things is my table is dynamic. I don't want to modify my script every time i have different data table. But my parametric data format is fix. So, it should have be an intelligent way to code this in JSL.
Highlighted
ian_jmp
Staff

Re: Stack Multiple Parameter with condition with JSL

Details will depend on exactly what you mean when you say 'my table is dynamic', and how much intelligence you require.

 

But, for instance, making some small changes to the JMP generated code, you could have;

NamesDefaultToHere(1);

sourceTable = DataTable("FINAL");
stackCols = 
{
		:Name( "2010;PinShort@CLK" ),
		:Name( "2011;PinShort@IO" ),
		:Name( "2012;PinShort@VDD" ),
		:Name( "2013;PinShort@LA" ),
		:Name( "2014;PinShort@LB" ),
		:Name( "2030;PinOpen@CLK" ),
		:Name( "2031;PinOpen@IO" ),
		:Name( "2032;PinOpen@VDD" ),
		:Name( "2033;PinOpen@LA" ),
		:Name( "2034;PinOpen@LB" ),
		:Name( "2200;Ana_Idd_noClock@VDD" ),
		:Name( "2360;Dig_ATE_FUN_00_001_Authenticate" ),
		:Name( "2361;Dig_ATE_FUN_00_003_DisableReset" ),
		:Name( "2380;Dig_ATE_FUN_00_004_GetVersion" ),
		:Name( "2440;SyncPulse_and_capResponse_0x90" ),
		:Name( "2441;Ana_Pads_ATE_VOL_0uA@IO" ),
		:Name( "2442;Ana_Pads_ATE_VOH_0uA@IO" ),
		:Name( "2443;Ana_Pads_ATE_VOL_0uA_IDD@VDD" ),
		:Name( "2444;Ana_Pads_ATE_VOL_0uA_Rcont_GND@VSS" )

};
resultTable = sourceTable << Stack(columns(stackCols), Source Label Column( "Label" ), Stacked Data Column( "Data" ));
resultTable << setName((sourceTable << getName)||" Stacked Data");

The values of 'sourceTable' and 'stackCols' would be set by a user interface, or some larger JSL script.

Highlighted
OneNorthJMP
Level IV

Re: Stack Multiple Parameter with condition with JSL

Hi Ian,

Thanks for reply. Maybe my explanation is not clear. I want to have JSL script can adapt different parameters from different input table.

For example, input table 1, i have 2 columns. I have to modified the JSL to below.

 

Data Table( "FINAL.jmp" ) << Stack(
	columns(
		:Name( "2010;PinShort@CLK" ),
		:Name( "2011;PinShort@IO" ),
		:Name( "2012;PinShort@VDD" ),
		:Name( "2013;PinShort@LA" ),
		:Name( "2014;PinShort@LB" ),
		:Name( "2030;PinOpen@CLK" )
	),
	Source Label Column( "Label" ),
	Stacked Data Column( "Data" )
)


For example, input table 2, if i have 3 columns. I have to modified the JSL to below.

 

Data Table( "FINAL.jmp" ) << Stack(
	columns( :Name( "2010;PinShort@CLK" ), :Name( "2011;PinShort@IO" ), :Name( "2012;PinShort@VDD" ), ),
	Source Label Column( "Label" ),
	Stacked Data Column( "Data" )
)


Then, what if i have thousand columns? Then i have to manually key in this one by one? or do this manually? Yes, of course i can do it manually. But that is not my objective, i want to have a script to can read the regular expression to find stack the parameters "(\d+);(\S+)" no matter what is my input table is.

Highlighted
txnelson
Super User

Re: Stack Multiple Parameter with condition with JSL

@OneNorthJMP ,

I believe that what Ian showed you is what you are asking for.  What Ian showed is that is what you need to do, is to create a list (stackCols) in your JSL that contains the names of the columns you want stacked, and then run the piece of code at the bottom of his script:

resultTable = sourceTable << Stack(columns(stackCols), Source Label Column( "Label" ), Stacked Data Column( "Data" ));
resultTable << setName((sourceTable << getName)||" Stacked Data");

So, the issue is for you to populate the stackCols list.  How you do that is unique to your needs.  It may be as easy as to use

stackCols = dt << get column names( continuous );

to populate the list.  Or it may require a more complex methodology.  But what Ian showed, is how simple it is to run the Stack Platform with whatever data that you currently have in your data table.

 

Jim
Highlighted
OneNorthJMP
Level IV

Re: Stack Multiple Parameter with condition with JSL

Hi Nelson,

I fully understand. And yet my issue is exactly what you mention above, "how to populate the stackCols list" with my condition with parametric with regular expression "(\d+);(\S+)".

Thanks anyway. I will try to trial and error myself.
Highlighted
pmroz
Super User

Re: Stack Multiple Parameter with condition with JSL

col_list = {"2010;PinShort@CLK", "2011;PinShort@IO", "2012;PinShort@VDD", "Label", "Data"};
stackcols = {};

for (i = 1, i <= nitems(col_list), i++,
	one_col = col_list[i];
	if (regex(one_col, "(\d+);(\S+)") == one_col,
		insertinto(stackcols, one_col);
	);
);
Highlighted
OneNorthJMP
Level IV

Re: Stack Multiple Parameter with condition with JSL

Thanks pmroz. I modified the script according to your suggestion, but seem like running into error.

Names Default To Here( 1 );

sourceTable = Data Table( "FINAL" );

col_list = sourceTable << get column names( continuous );
stackcols = {};
one_col = {};

For( i = 1, i <= N Items( col_list ), i++,
	one_col = col_list[i];
	If( Regex( one_col, "(\d+);(\S+)" ) == one_col,
		Insert Into( stackcols, one_col )
	);
);

resultTable = sourceTable << Stack(
	columns( stackcols ),
	Source Label Column( "Label" ),
	Stacked Data Column( "Data" )
);
resultTable << setName( (sourceTable << getName) || " Stacked Data" );


/***********************************
Unknown error in pattern match in access or evaluation of 'Regex' , Regex/*###*/(one_col, "(\d+);(\S+)")

Highlighted
pmroz
Super User

Re: Stack Multiple Parameter with condition with JSL

You needed to convert the column names to a string.  Also one_col is not a list.  Here's the corrected code.  I encourage you to 

a) Read the scripting manuals

b) Check the log frequently for variable values, error messages etc.

c) Keep using this discussion forum

 

Names Default To Here( 1 );

sourceTable = Data Table( "FINAL" );

col_list = sourceTable << get column names( continuous, string );
stackcols = {};
//one_col = {};

For( i = 1, i <= N Items( col_list ), i++,
	one_col = col_list[i];
	show(one_col, i);
	If( Regex( one_col, "(\d+);(\S+)" ) == one_col,
		Insert Into( stackcols, one_col )
	);
);

resultTable = sourceTable << Stack(
	columns( stackcols ),
	Source Label Column( "Label" ),
	Stacked Data Column( "Data" )
);
resultTable << setName( (sourceTable << getName) || " Stacked Data" );

View solution in original post

Article Labels

    There are no labels assigned to this post.