Select Columns Based on Words Contained in HeaderI have an analysis I'd like to perform but I need to select several columns based on the words contained in the header befre I can do this, currently I do this manually but this is painfully slow and I can miss some columns if I'm not careful.
in the image example I would like to select the 2 columns starting 'What colors' but none of the other 4. They can be spread amongst other columns and the number of them will be different per experiment. Once selected I can then extract them and perform the analysis.
This needs to be done automatically without any user input involved and I can't find any jsl that does this but I'm sure it must exist, it's just that I haven't been able to find it or don't know the correct scripting term.

Regards
David
Automation and ScriptingRe: Select Columns Based on Words Contained in HeaderThanks!Re: Select Columns Based on Words Contained in HeaderThe Contains() function does not return a Boolean of 0 or 1, it returns the character location where the comparison was found.
Try using
Contains( colList[i], "N" ) > 0
Re: Select Columns Based on Words Contained in HeaderI am trying to use this script to select columns that contain a string within the middle of the column name. When I put "P" or "PN" in the contains() it works, but not when I insert "N" or "NP" or "NP3".
Thanks
For( i = 1, i <= N Items( colList ), i++,
If(
// Put in any selection criteria you want
//Left( colList[i], 2 ) == "PN" ,
// or it could be
Contains( colList[i], "N" ) == 1
,
Column( dt, colList[i] ) << set selected
)
);
Re: Select Columns Based on Words Contained in Headerthank you very much, this works perfectly
Re: Select Columns Based on Words Contained in HeaderI don't think this adds anything given the 'no user input' requirement. But I wanted to take the chance to mention that column filtering is pretty handy when working interactively (and is easy to overlook). Sometimes people use scripts because they think it's 'hard' via the UI.
The 'Filter Col Selector' is also scriptable:
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
New Window( "Filter Col Selector Example", fcs = Filter Col Selector( DataTable("Big Class") ));
// See what messages the 'Filter Col Selector' understands
ShowProperties(fcs);
// Try it out
Print(fcs << GetItems);
Wait(3);
fcs << NameContains("ei");
Print(fcs << getItems);Re: Select Columns Based on Words Contained in HeaderHere is a very simple way of doing what you are requesting, and it is expandable into much more complex requirements
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/semiconductor capability.jmp" );
colList = dt << get column names( string );
dt << clear column selection;
For( i = 1, i <= N Items( colList ), i++,
If(
// Put in any selection criteria you want
Left( colList[i], 2 ) == "PN" ,
// or it could be
// contains( colList[i], "PN") == 1,
Column( dt, colList[i] ) << set selected
)
);
If( N Items( dt << get selected columns ) > 0,
dtSelected = dt << subset( selected rows( 0 ), selected columns( 1 ) )
);