cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
miguello
Level VI

How to get names of the selected columns in string format

In my script I use the following to get the list of all columns in a string format:

columnNames = dt << Get Column Names( string );

I need that so I could iterate through them using "For Each" loop:

For Each( {columnName, index}, columnNames, Column( dt, columnName ) << Set Name( columnName ||"SomethingHere" ) );

Now I need to only get selected columns and run the same loop on them.

I know only one way to get selected columns:

columnNames = dt << Get Selected Columns;

but it returns references to columns, not string names. So when I run this then:

For Each( {columnName, index}, columnNames, Column( dt, columnName ) << Set Name( columnName ||"SomethingHere" ) );

it doesn't work.

How do I either

1. Rewrite For Each loop (I'd like to keep using this loop instead of For loop) to accept references to columns as well

or

2. Convert references to columns into a list of strings.

 

?

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: How to get names of the selected columns in string format

Add (String) to Get Selected Columns (not documented in scripting index... but help has "a bit more" documentation dt<<Get Selected Properties(<{list of properties}>) )

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
dt << Select Columns({:sex, :height});

sel_colnames = dt << Get Selected Columns(string); 
show(sel_colnames); // sel_colnames = {"sex", "height"};

 

 

-Jarmo

View solution in original post

5 REPLIES 5
miguello
Level VI

Re: How to get names of the selected columns in string format

Ok, I solved it the following way.

Before running my already scripted "For Each" loop that I doin't want to change, I run this:

For Each( {columnName, index}, columnNames, columnNames[index] = columnNames[index]<< Get Name );

Any other options?

jthi
Super User

Re: How to get names of the selected columns in string format

Add (String) to Get Selected Columns (not documented in scripting index... but help has "a bit more" documentation dt<<Get Selected Properties(<{list of properties}>) )

Names Default To Here(1);
dt = Open("$SAMPLE_DATA/Big Class.jmp");
dt << Select Columns({:sex, :height});

sel_colnames = dt << Get Selected Columns(string); 
show(sel_colnames); // sel_colnames = {"sex", "height"};

 

 

-Jarmo
miguello
Level VI

Re: How to get names of the selected columns in string format

Awesome! **bleep** under-documentation

jthi
Super User

Re: How to get names of the selected columns in string format

Would be good to report. I just don't remember who was supposed to be tagged when Scripting Index was lacking so for now lets tag @Jeff_Perkinson and@Ryan_Gilmore , << Get Selected Columns is missing optional option parameters in Scripting Index.

-Jarmo

Re: How to get names of the selected columns in string format

@miguello, @jthi  - JMP Technical Support will make the request to update the Scripting Index. Thank you for sharing!

Duane Hayes