Sorry for my misinformation. I misread the structure of the Categories data table. Below is a script that creates a couple of data tables, and a categories table and then expands the data tables and finally renames the columns based upon the entries in the categories data table. I hope this gets us back on track. The script will work on as many data tables as necessary. All that has to be done, is to add to the dataTableList list, all of the data tables to be processed
Names Default To Here( 1 );
// This example script opens up 2 data tables and 1 category table.
// In reality, as many as necessary data tables could be used
// Create the tables
dt1 = New Table( "Table1",
Add Rows( 3 ),
New Column( "Category", Character, "Nominal", Set Values( {"ABC", "ABC", "ABC"} ) ),
New Column( "DATA", Character( 33 ), "Nominal", Set Values( {"123.56.8.342", "431.02.0.567", "318.00.1.816"} ), Set Display Width( 182 ) )
);
dt2 = New Table( "Table2",
Add Rows( 3 ),
New Column( "Category", Character, "Nominal", Set Values( {"B", "B", "B"} ) ),
New Column( "Data", Character, "Nominal", Set Values( {"13.24", "98.44", "63.89"} ) )
);
dtCat = New Table( "The Categories",
Add Rows( 13 ),
New Column( "Category",
Character,
"Nominal",
Set Values( {"ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "ABC", "B", "B", "B", "B"} ),
Set Display Width( 67 )
),
New Column( "Width", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1, 2, 3] ) ),
New Column( "Label",
Character( 16 ),
"Nominal",
Set Values(
{"label0.0", "label0.1", "label0.2", "label0.3", "label0.4", "label0.5", "label0.6", "label0.7", "label0.8", "thelabel.1", "thelabel.2",
"thelabel.3", "thelabel.4"}
),
Set Display Width( 99 )
)
);
// Below this line, is the script that will add the new columns to each of the data tables
// and will take the names from the dtCat (Categories) data table and change the names to
// the columns in each of the data tables
// Create a list of the pointers to the data tables. This will allow for the using of the list
// entries to point to the data tables using a subscript
dataTableList = {};
insert into(dataTableList, dt1 );
insert into(dataTableList, dt2 );
// Loop across the data table list and expand the columns based upon the the column called Data
For( i = 1, i <= N Items( dataTableList ), i++,
ncols_to_add = length( substitute((dataTableList[i]:Data)[1],".",""));
For( k = 1, k <= ncols_to_add, k++, // the || operator joins two strings
dataTableList[i] << New Column( "c" || Char( i ),
Numeric,
Continous,
<<Set Each Value( Num( Substr( Regex( :data, "\D", "", GLOBALREPLACE ), k, 1 ) ) )
)
)
);
// Now rename the columns in each of the data tables based upon the labels in the Category table
For( i = 1, i <= N Items( dataTableList ), i++,
// Subset the dtCat table into the a new data table with just the one
// category being processed
dtCat << select where( :Category == (dataTableList[i]:Category)[1] );
dtSub = dtCat << subset( selected rows == 1, selected columns( 0 ) );
// set the offset of where to start the renaming
offset = 2;
// Loop
// Change names in dt1 to match the Label in
For( k = 1, k <= N Rows( dtSub ), k++,
Column( dataTableList[i], k + offset ) << set name( dtSub:Label[k] )
);
Close( dtSub, nosave );
);
Jim