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
hbkqqq
Level I

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.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
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

View solution in original post

2 REPLIES 2
Highlighted
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

View solution in original post

Highlighted
hbkqqq
Level I

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

Thank you txnelson.

Article Labels

    There are no labels assigned to this post.