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
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" );
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':
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).
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.
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.