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
ConfidenceOwl94
Level III

Assign variable to table based on the contain of the table name.

I have multiple table that are open and need to assign variable based on a contain(DC1,DC2,DC3) of the table name. If table name contain DC1 assign dt1, if it Table name contain DC2 assign dt2....

 

Table 1: ABC_25C_DC1_2024

Table 2: ABC_25C_DC2_2024

Table 3: ABC_25C_DC3_2024

 

Here is the command line that i was try to work with. 

 

tablelist = Get Data Table List() << get name;
 
If(Contains(Concat Items(tablelist), "DC1"),
dt2= XXXXXXXXX
);

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: Assign variable to table based on the contain of the table name.

If you can be 100% sure about the names, then I would store them into a list

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

New Table("ABC_25C_DC1_2024");
New Table("ABC_25C_DC2_2024");
New Table("ABC_25C_DC3_2024");


tablelist = Get Data Table List() << get name;

dc_tables = {};

For Each({tablename}, tablelist,
	If(Starts With(tablename, "ABC_25C_DC"), // some pattern to catch correct tables
		Insert Into(dc_tables, Datatable(tablename));
	);
);

You can then access them with dc_tables[1] and so on.

-Jarmo

View solution in original post

jthi
Super User

Re: Assign variable to table based on the contain of the table name.

I don't think that provides any additional clarification to me, expect that you can capture the table "type" after last _. If you can capture table "type" from the end (after last _) you can use Associative Array (or still a list). You can use Word to capture the last part of name

Names Default To Here(1);

str = "ABC_25C_DC1_2024";

last_part = Word(-1, str, "_");

Final idea would still be the same, find some way of getting references to your tables, store them into some data structure (list or associative array), get the tables from that data structure when needed using index (list) or key (associative array).

-Jarmo

View solution in original post

5 REPLIES 5
jthi
Super User

Re: Assign variable to table based on the contain of the table name.

How do you open those tables? Could you create references during that process? I would also store those into a list instead of trying to use separate dt1, dt2, dt3... for them.

-Jarmo
ConfidenceOwl94
Level III

Re: Assign variable to table based on the contain of the table name.

They are created by some other automated JMP script that I don't have access to.

jthi
Super User

Re: Assign variable to table based on the contain of the table name.

If you can be 100% sure about the names, then I would store them into a list

Names Default To Here(1);

dt = Open("$SAMPLE_DATA/Big Class.jmp");

New Table("ABC_25C_DC1_2024");
New Table("ABC_25C_DC2_2024");
New Table("ABC_25C_DC3_2024");


tablelist = Get Data Table List() << get name;

dc_tables = {};

For Each({tablename}, tablelist,
	If(Starts With(tablename, "ABC_25C_DC"), // some pattern to catch correct tables
		Insert Into(dc_tables, Datatable(tablename));
	);
);

You can then access them with dc_tables[1] and so on.

-Jarmo
ConfidenceOwl94
Level III

Re: Assign variable to table based on the contain of the table name.

 

I hope this will clarify further of what I am trying to achieve.

 

ConfidenceOwl94_1-1711648238903.png

 

jthi
Super User

Re: Assign variable to table based on the contain of the table name.

I don't think that provides any additional clarification to me, expect that you can capture the table "type" after last _. If you can capture table "type" from the end (after last _) you can use Associative Array (or still a list). You can use Word to capture the last part of name

Names Default To Here(1);

str = "ABC_25C_DC1_2024";

last_part = Word(-1, str, "_");

Final idea would still be the same, find some way of getting references to your tables, store them into some data structure (list or associative array), get the tables from that data structure when needed using index (list) or key (associative array).

-Jarmo