Choose Language Hide Translation Bar
Highlighted
MarkDayton
Level IV

Get Column Names from List of Columns

 

Names Default to Here(1);
dt = Current Data Table();

column list = dt << Get Column Names(Continuous);
key list = dt << Get Column Group("KEYS");

"column list" contains a list of names from columns containing continuous data.

"key list" contains a list of columns in the "KEYS" group. 

 

How do I get the names of the columns from "key list"? Ultimately I would like to remove any continuous column names from the "column list" that are in the "KEYS" group. I found a post from Craige Hales to manage the lists, but I need to get them in the same format.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
MarkDayton
Level IV

Re: Get Column Names from List of Columns

Here is the solution I arrived at after converting the key list to strings as suggested:

 

// Initialize
Names Default to Here(1);
dt = Current Data Table();
key list names  = {};

// Get a list of all continuous columns
column list = dt << Get Column Names(Continuous, String);

// Create a list of column names in the KEYS group
key list = dt << Get Column Group("KEYS");
For(i = 1, i <= N Items(key list), i++,
	Insert Into(key list names, Char(key list[i]))
); 

// Remove from the column list any column that is in the KEYS group
/* 
Adapted from - Re: Quick way to compare two lists (uncommon elements)? JAN 10, 2017 6:41 AM, by Craige_Hales, STAFF (RETIRED) */ set1 = Associative Array(column list); set2 = Associative Array(key list names); // Find the names common to both lists intersection = set1; intersection << Intersect(set2); // Remove the common names cleaned list = set1; cleaned list << Remove(intersection); column list = cleaned list << Get Keys;

View solution in original post

4 REPLIES 4
Highlighted
txnelson
Super User

Re: Get Column Names from List of Columns

What is returned from both the << Get Column Names, and << Get Column Group are JMP lists.  You can roughly think of them as Arrays of values.  Please review the Scripting Guides section on using lists.

Below is a modification of your code, that will check for the comparison between 2 lists, for column names found common in both lists and then removing them from the Key List, list.  Please note, that the Contains function requires literal strings for it to function, so that is why the <<get column names has the "string" option added to it, and that the Contains() function has the search element from the Keys List, converted to a character string before the search across the Column Names list.

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/semiconductor capability.jmp" );

column list = dt << Get Column Names( Continuous, string );
key list = dt << Get Column Group( "Processes" );
Show( "complete list", key list );

For( i = N Items( key list ), i >= 1, i--,
	If( Contains( column list, Char( key list[i] ) ),
		key list = Remove( key list, i, 1 )
	)
);
Show( "final list", key list );

In my example, the Keys List ends up not having any values, since all elements in the group are numeric columns

Jim
Highlighted
MarkDayton
Level IV

Re: Get Column Names from List of Columns

Thanks. I am looking to remove from "column list" any name that is in the "Processes" group (using your example), so items need to be removed from "column list", not "key list". I expect that I will need to search column list for Char(key list[i]) and if found remove it.
Highlighted
MarkDayton
Level IV

Re: Get Column Names from List of Columns

Here is the solution I arrived at after converting the key list to strings as suggested:

 

// Initialize
Names Default to Here(1);
dt = Current Data Table();
key list names  = {};

// Get a list of all continuous columns
column list = dt << Get Column Names(Continuous, String);

// Create a list of column names in the KEYS group
key list = dt << Get Column Group("KEYS");
For(i = 1, i <= N Items(key list), i++,
	Insert Into(key list names, Char(key list[i]))
); 

// Remove from the column list any column that is in the KEYS group
/* 
Adapted from - Re: Quick way to compare two lists (uncommon elements)? JAN 10, 2017 6:41 AM, by Craige_Hales, STAFF (RETIRED) */ set1 = Associative Array(column list); set2 = Associative Array(key list names); // Find the names common to both lists intersection = set1; intersection << Intersect(set2); // Remove the common names cleaned list = set1; cleaned list << Remove(intersection); column list = cleaned list << Get Keys;

View solution in original post

Highlighted
MarkDayton
Level IV

Re: Get Column Names from List of Columns

The trick was: Char(key list[i]))
(I never thought of casting the column reference into a string)
Article Labels

    There are no labels assigned to this post.