cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP will suspend normal business operations for our Winter Holiday beginning on Wednesday, Dec. 24, 2025, at 5:00 p.m. ET (2:00 p.m. ET for JMP Accounts Receivable).
    Regular business hours will resume at 9:00 a.m. EST on Friday, Jan. 2, 2026.
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
KinKame
Level IV

using table name as variable

hello

I would like to rename 3 tables and I tried to use a for loop as below, but without results so far.

Does anyone get any idea?

tb_list = {"SPC_tb", "SPEC_tb", "Data_tb"};

dtt = Data Table(tb_list[1]) << Get Selected;

For( k = 1, k < 4, k++,

  dtt = Data Table( eval(tb_list) << Get Selected[1] );

  name_list = dtt << get column names();

  column_name_tb = New Table( "xx_temp_name_table" );

  column_name_tb << New Column( "name", Character, Set Values( name_list ) );

  column_name_tb << New Column( "rename", formula( "rule" || :name ) );

  rename_list = Column( column_name_tb, "rename" ) << getValues;

  For( i = 1, i < N Col(dtt) + 1, i++,

  Eval( Column( dtt, i ) << set name( rename_list ) )

  )

);

Lionel

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: using table name as variable

I am not absolutely sure as to what you are attempting to do, however, if what I am detecting is the purpose of your code is to rename the columns in 3 data table, here is a piece of code that will do it:

Names Default To Here( 1 );

tb_list = {"SPC_tb", "SPEC_tb", "Data_tb"};

For( k = 1, k <= 3, k++,

   dtt = Data Table( tb_list );

   For( i = 1, i < N Col( dtt ), i++,

      Column( dtt, i ) << set name( "rule" || Char( Column( dtt, i ) << get name ) )

       );

);

Jim

View solution in original post

2 REPLIES 2
txnelson
Super User

Re: using table name as variable

I am not absolutely sure as to what you are attempting to do, however, if what I am detecting is the purpose of your code is to rename the columns in 3 data table, here is a piece of code that will do it:

Names Default To Here( 1 );

tb_list = {"SPC_tb", "SPEC_tb", "Data_tb"};

For( k = 1, k <= 3, k++,

   dtt = Data Table( tb_list );

   For( i = 1, i < N Col( dtt ), i++,

      Column( dtt, i ) << set name( "rule" || Char( Column( dtt, i ) << get name ) )

       );

);

Jim
KinKame
Level IV

Re: using table name as variable

works nicely. Good detection :)

my mistake was to input in the list not the table name but the object associated.

SPC_tb = data table("SPC").

thank you!

Recommended Articles