cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Due to the recently reported Microsoft outage, users may be temporarily unable to access My JMP or experience a delay receiving their verification codes. If you have previously installed JMP on your computer, this outage should not impact your ability to access the software. My JMP services will be restored as soon as Microsoft resolves this issue.
  • Image to Table JMP extension imports single or batch images as data tables. Useful to extract curves from pictures or convert image data to curve data to use in analyses like Functional Data Explorer. Download and install the extension.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
ShahirahLoqman
Level II

Script to Delete Columns Not Containing a Certain Word

Hi, how do I write a script to delete columns not containing a certain word? I would like to delete column names that do not have the word "4C4QC30.0" in them

Column.PNG

 

My script below unfortunately does not work:

 

For( i = 11, i <= N Cols( dt1_new ), i++, // set number of columns to start looking at

If( (Column( dt1_new, i ) << Get Name) != "4C4QC30.0.Cv", //

dt1_new << Delete Column ;

 

)

);

 

thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: Script to Delete Columns Not Containing a Certain Word

Here are the minor changes to your code to make it work.  Note the looping going from the last column to your 11th column.  That allows for using the column number for deleting.

Names Default To Here( 1 );
dt1_new = Current Data Table();

For( i = N Cols( dt1_new ), i >= 11, i--, // set number of columns to start looking at
	If( Contains( Column( dt1_new, i ) << Get Name, "4C4QC30.0.Cv" ) == 0,
		dt1_new << Delete Columns( i )
	)
);
Jim

View solution in original post

1 REPLY 1
txnelson
Super User

Re: Script to Delete Columns Not Containing a Certain Word

Here are the minor changes to your code to make it work.  Note the looping going from the last column to your 11th column.  That allows for using the column number for deleting.

Names Default To Here( 1 );
dt1_new = Current Data Table();

For( i = N Cols( dt1_new ), i >= 11, i--, // set number of columns to start looking at
	If( Contains( Column( dt1_new, i ) << Get Name, "4C4QC30.0.Cv" ) == 0,
		dt1_new << Delete Columns( i )
	)
);
Jim

Recommended Articles