- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Deleting columns that are not in a list
I have a set of columns that I want to keep and then delete all except this set.
The columns that I want to delete are large in number.
Is there any easy way to do this using a script?
Thanks.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Deleting columns that are not in a list
Example
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Deleting columns that are not in a list
Example
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Deleting columns that are not in a list
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Deleting columns that are not in a list
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Deleting columns that are not in a list
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Deleting columns that are not in a list
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)
)
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Deleting columns that are not in a list
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Deleting columns that are not in a list
"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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Deleting columns that are not in a list
I'm interested to subset only columns containing keywords. And not the full column names only (since I have a lot of data).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Deleting columns that are not in a list
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/