Slightly different bu the same idea, the following code deletes columns that are in a list. Specifically you have a list of columns (all), and items are removed if they are contained in the list excl.
all = dt << Get Column Names(string);
// assume excl is a list of column names that i want to remove
For (i=1,i<=NItems(excl),i++,
pos = Contains(all,excl[i]);
If (pos>0,
RemoveFrom(all,pos)
)
);
"There's a million ways to get things done..." Talking Heads, "What A Day That Was", 1984
If the number of columns to be deleted is truly large, it might be more efficient to Subset the table with all rows, keeping only the columns in your list. That could save lots of iterative deletion.
Your application might not be that easy, though.
Sorry, maybe I misuunderstood. The code removes items from the list not from the table. But the updated list can be used with a Subset command to generate a subset table only with the columns you are interested in.
More here: http://www.pega-analytics.co.uk/blog/scripting-table-subsets/