Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted
d_barnett
Level IV

Select Columns Based on Words Contained in Header

I 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.

 

Capture.JPG

 

Regards

 

David

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
txnelson
Super User

Re: Select Columns Based on Words Contained in Header

Here 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 ) )
);
Jim

View solution in original post

3 REPLIES 3
Highlighted
txnelson
Super User

Re: Select Columns Based on Words Contained in Header

Here 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 ) )
);
Jim

View solution in original post

Highlighted
ian_jmp
Staff

Re: Select Columns Based on Words Contained in Header

I 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);
Highlighted
d_barnett
Level IV

Re: Select Columns Based on Words Contained in Header

thank you very much, this works perfectly