cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
chris_dennis
Level III

JSL change part of col name based on values from another table

After running a general query to collect lots of data with general header of bin01, bin02, .... bin16.  I want to update column headers based on a different able that has bin information based on recipe.  This seems an easy task using a munger command, but errors when placed into a nested loop.  Same syntax works in a single loop format, but since there will be a variable number of bin values to replace 1 to 16 possible a loop structure is preferred.  I have attached sample data tables and JSL.  Any recommendations are appreciated.  Working on this issue using JMP16.1

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: JSL change part of col name based on values from another table

Here is a rework of your script that works with your sample data tables.  The main change is the addition of the Try() function, that keeps the code from stopping when an error within the Set () occures.

			//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	Need to update data table based on bins in recipe, name and get rid of Bin Cols no data was collected, bins greater that number defined by bin size list
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  	Referance: https://community.jmp.com/t5/JMP-Scripts/Find-amp-Replace-for-Column-Names/ta-p/217124
b = Data Table( "BinSizeList" ):Name( "CntBins" ) << get values;
Show( b );
Show( b[1] );
bnum = Data Table( "BinSizeList" ):Name( "Label" ) << get values;
Show( bnum );
bsize = Data Table( "BinSizeList" ):Name( "Bin_Label" ) << get values;
Show( bsize );
			
Data Table( "LPD_Data" ) << Select Columns( ALL );
cols = Data Table( "LPD_Data" ) << Get Selected Columns();
Show( cols );

//			Nested loop does not work?  Error on "set name" comand only when nested j loop is included.  Works fine if j for statement is removed and [ j ] replaced with a valid number
			
For( i = 1, i <= N Items( cols ), i++,
	For( j = 1, j <= b[1], j++,
		Try(
			cols[i] << set name(
				Munger(
					Char( cols[i] ), // << get name,
					1,
					Eval( Char( bnum[j] ) ),
					Eval( Char( bsize[j] ) )
				)
			)
		)
	)
);
			

Jim

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: JSL change part of col name based on values from another table

Here is a rework of your script that works with your sample data tables.  The main change is the addition of the Try() function, that keeps the code from stopping when an error within the Set () occures.

			//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	Need to update data table based on bins in recipe, name and get rid of Bin Cols no data was collected, bins greater that number defined by bin size list
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//  	Referance: https://community.jmp.com/t5/JMP-Scripts/Find-amp-Replace-for-Column-Names/ta-p/217124
b = Data Table( "BinSizeList" ):Name( "CntBins" ) << get values;
Show( b );
Show( b[1] );
bnum = Data Table( "BinSizeList" ):Name( "Label" ) << get values;
Show( bnum );
bsize = Data Table( "BinSizeList" ):Name( "Bin_Label" ) << get values;
Show( bsize );
			
Data Table( "LPD_Data" ) << Select Columns( ALL );
cols = Data Table( "LPD_Data" ) << Get Selected Columns();
Show( cols );

//			Nested loop does not work?  Error on "set name" comand only when nested j loop is included.  Works fine if j for statement is removed and [ j ] replaced with a valid number
			
For( i = 1, i <= N Items( cols ), i++,
	For( j = 1, j <= b[1], j++,
		Try(
			cols[i] << set name(
				Munger(
					Char( cols[i] ), // << get name,
					1,
					Eval( Char( bnum[j] ) ),
					Eval( Char( bsize[j] ) )
				)
			)
		)
	)
);
			

Jim
chris_dennis
Level III

Re: JSL change part of col name based on values from another table

Thanks, for your help.  I had not seen the TRY command before.  Worked great.