Subscribe Bookmark RSS Feed

Re: Change multiple data table names product of a subset

ana_v

Community Trekker

Joined:

Oct 6, 2015

I would like to change in batch the name of multiple opened tables which are a product of a Table subset.

If I use the following script to subset a table named "MyData.jmp", I get tables with the name of the original table followed by a space and a sequential number (e.g. "MyData 1", "MyData 2", "MyData 3" , "MyData n"). Instead I would like to give each table the name of the specific level of the column by which it has been subset (as explained after the script).

//Subset a Data Table (By different column levels).

Data Table( "MyData.jmp" ) <<

Subset(

    By( :Ref ),

    All rows,

    Selected columns only( 0 ),

    columns(

        :day,

        :month,

        :grid,

        :Ref

    )

)

On the other hand, it if I subset the table ("MyData.jmp") using the interface I get table names such as "Ref=P100_1", "Ref=P100_2", "Ref=P100_25". Meaning that I have subset the table by the column "Ref" and after the "=" the levels of the column that by which I have subset appear. In this case I am interested in having just the part "P100_1", "P100_2", "P100_25" as the names of the tables. In this case I would need to delete in batch the same text from all of the data tables ("Ref=").

2 REPLIES
ian_jmp

Staff

Joined:

Jun 23, 2011

Here's one way:

// Eaxample table

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

// Example column

col = Column(dt, "age");

// Make subsets by :age

colLevs = AssociativeArray(col) << getKeys;

For (i=1, i<=NItems(colLevs), i++,

r2get = dt << getRowsWhere(:age == colLevs[i]);

dtSub = dt << Subset(Rows(r2get));

dtSub << setName(Char(colLevs[i]));

);



Highlighted
ana_v

Community Trekker

Joined:

Oct 6, 2015

Thanks Ian@JMP!

The script worked very nicely indeed.

I introduced the "invisible" factor to the sub tables to avoid having many windows open and then save them as a text file (with another script). It seems to have worked also fine.

// Eaxample table

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

// Example column

col = Column(dt, "age");

// Make subsets by :age

colLevs = AssociativeArray(col) << getKeys;

For (i=1, i<=NItems(colLevs), i++,

  r2get = dt << getRowsWhere(:age == colLevs[i]);

  dtSub = dt << Subset("Invisible", Rows(r2get));

  dtSub << setName(Char(colLevs[i]));

);