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
Tavuk89
Level II

Recode Multiple Column Group Name with jsl

I have column groups that needed frequent recoding. It works just by copying the enhanced log but how do I combine them together so that the code is less clunky?

// Open Data Table: Big Class.jmp
// → Data Table( "Big Class" )
Open( "$SAMPLE_DATA/Big Class.jmp" );


// Change column name: name → Student's name
Data Table( "Big Class" ):name << Set Name( "Student's name" );


// Change column name: age → Student's age
Data Table( "Big Class" ):age << Set Name( "Student's age" );
1 REPLY 1
txnelson
Super User

Re: Recode Multiple Column Group Name with jsl

You can use the Column Name Recode

     Cols=>Column Names=>Recode Column Names....

If you do it once, you will see the JSL in the log as to what the JSL was that will create recodes

// Recode column names
Local( {dt = Data Table( "Big Class" ), names},
	names = Recode(
		dt << Get Column Names( String ),
		{Map Value(
			_rcOrig,
			{"age", "s age", "height", "s height", "name", "s name", "sex", "s sex",
			"weight", "s weight"},
			Unmatched( _rcNow )
		)}
	);
	For Each( {name, i}, names, Column( dt, i ) << Set Name( name ) );
);

It is also pretty easy to get a list of column names, and from that, make names changes across all of the columns.

Names Default To Here( 1 );
dt = Current Data Table();

nameList = dt << get column names( string );

For Each( {col}, nameList,
	Column( col ) << set name( "Student's " || col )
);
Jim