BookmarkSubscribe
Choose Language Hide Translation Bar
hbkqqq
New Contributor

How can I rename names in a for loop?

Hello, I'm new to the JMP Script, and I searched a lot in the forum, but didn't get a answer for my question.

Basically I did a for loop and each will generate a new table. I want to rename the column BBB to XXX(i), such as column XXX(1) for the first new table, column XXX(2) for the second new table, XXX(3) for the third new table ... column XXX(10) for the last one and then merge all the new tables, so that there will be only one big table with columns XXX(1), XXX(2)...XXX(10)

 

Here is my script:

For( i = 1, i <= 10, i++,
dt << Summary(
Group( :AAA), N( :BBB ), Freq( "None" ), Weight( "None" )
);
:N (BBB) << Set Name (XXX(i));
);

);

 

 

But I couldn't get I want.

Could you guys help me? I appreciate any suggestion.

 

 

0 Kudos
1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How can I rename names in a for loop?

There are a couple of issues with your code

  1. The column name created in the Summary Platform is "N( BBB )".  When you reapply it into a JMP statement, JMP interprets it as a function, N() with an argument of "BBB".  To fix this, use the :Name() function.
  2. The argument for << Set Name() needs to be a character string.

See the script below for the corrections

For( i = 1, i <= 10, i++,
	dtSum = dt << Summary(
		Group( :AAA ),
		N( :BBB ),
		Freq( "None" ),
		Weight( "None" )
	);
	:Name( "N( BBB )" ) << Set Name( "XXX(" || Char( i ) || ")" );
);
Jim
2 REPLIES 2
txnelson
Super User

Re: How can I rename names in a for loop?

There are a couple of issues with your code

  1. The column name created in the Summary Platform is "N( BBB )".  When you reapply it into a JMP statement, JMP interprets it as a function, N() with an argument of "BBB".  To fix this, use the :Name() function.
  2. The argument for << Set Name() needs to be a character string.

See the script below for the corrections

For( i = 1, i <= 10, i++,
	dtSum = dt << Summary(
		Group( :AAA ),
		N( :BBB ),
		Freq( "None" ),
		Weight( "None" )
	);
	:Name( "N( BBB )" ) << Set Name( "XXX(" || Char( i ) || ")" );
);
Jim
hbkqqq
New Contributor

Re: How can I rename names in a for loop?

Thank you txnelson.

0 Kudos