I reworked the previous script to meet your new requirements.
Names Default To Here( 1 );
dt = Current Data Table();
keep = {};
delete = {};
colNameList = dt << get column names( string );
numericNamesOnly = colNameList;
For( i = N Items( colNameList ), i >= 1, i--,
colNameList[i] = Uppercase( colNameList[i] );
If( Is Missing( Num( colNameList[i] ) ) == 1,
numericNamesOnly[i] = ""
);
);
While( N Items( colNameList ) > 0,
If(
Contains( colNameList[1], Uppercase( "Date début" ) ),
found = Contains( numericNamesOnly, Word( 3, colNameList[1] ) );
If( found > 0,
Insert Into( keep, colNameList[1] );
Insert Into( keep, numericNamesOnly[found] );
Remove From( numericNamesOnly, found, 1 );
Remove From( numericNamesOnly, 1, 1 );
Remove From( colNameList, found, 1 );
Remove From( colNameList, 1, 1 );
,
Insert Into( delete, colNameList[1] );
Remove From( colNameList, 1, 1 );
Remove From( numericNamesOnly, 1, 1 );
);,
Is Missing( Num( colNameList[1] ) ) == 0,
found = Contains( colNameList, Uppercase( "DATE début " ) || colNameList[1] );
If( found > 0,
Insert Into( keep, colNameList[1] );
Insert Into( keep, dateDebutOnly[found] );
Remove From( numericNamesOnly, found, 1 );
Remove From( numericNamesOnly, 1, 1 );
Remove From( colNameList, found, 1 );
Remove From( colNameList, 1, 1 );
,
Insert Into( delete, colNameList[1] );
Remove From( colNameList, 1, 1 );
Remove From( numericNamesOnly, 1, 1 );
);,
Remove From( colNameList, 1, 1 );
Remove From( numericNamesOnly, 1, 1 );
)
);
dt << delete columns(delete);
It isn't pretty code, but it shows the direct way to get the job done.
Note: You have an error in your sample data table. You have a column name "Datd début 952" that needs to be changed to "Date début 952"
Thanks it works!
I tried to use your script but initially I didn't know how to characterize all the columns of the second group because there are no similar terms.
Hello everyone, I have a data table similar to this one:
The database consists of 2 groups:
- The dates ("start date...")
- Numbers associated with operations
My goal is to remove the columns that are not in the intersection of the two column groups.
That is to say here, I would like to automatically delete with a script the columns: "Start date 952", "9950"
Thanks for your help !
Thank you for saving my day too. 