cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
user8421
Level II

JSL to Delete Columns Based on Column Names

Hi everyone!

I am looking for a script that will pull the data table column names and if the column name starts with the word "Raw" to select and delete that column.

My script is attached below, but it has 2 issues that I cannot resolve.

1) The contains function only searches the column name for containing the string "Raw."  Is there a way that I can specify to only select and delete the columns that START with the string "Raw"?

2) I get an error for the syntax I have used for deleting the column.

dt = Current Data Table()

ColNamesList = dt << Get Column Names;

Ncols = N Items(ColNamesList);

For(
	i=1,
	i<=NCols,
	i++,
	If(
		Contains(Char(ColNamesList[i]), "Raw"),
		dt << Delete Column(:Name(Char(ColNamesList[i])))
	)
);

Any help appreciated!

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
Thierry_S
Super User

Re: JSL to Delete Columns Based on Column Names

Hi,
A couple of notes (Sorry, I don't have the time right now to provide a complete solution)
1) Specify the format of the output of the "Column Get Names" function as text by replacing the second line of your code with:
ColNamesList = dt << Get Column Names(string); you won't need to use the statement "Char" function in your code below
2) When deleting an unknown number of columns, it is best to start from the last column and to progress backward:
For (i = NCols, i>=1, i--, ....
3) You may want to simplify your delete line of code by simply using: dt << Delete Column (Column (i))

Best,
TS
Thierry R. Sornasse

View solution in original post

gzmorgan0
Super User (Alumni)

Re: JSL to Delete Columns Based on Column Names

@user8421 ,

 

@Thierry_S provide you ith excellent suggestions.  Also look up the character function Starts With(ColNameList[i], "Raw")

View solution in original post

2 REPLIES 2
Thierry_S
Super User

Re: JSL to Delete Columns Based on Column Names

Hi,
A couple of notes (Sorry, I don't have the time right now to provide a complete solution)
1) Specify the format of the output of the "Column Get Names" function as text by replacing the second line of your code with:
ColNamesList = dt << Get Column Names(string); you won't need to use the statement "Char" function in your code below
2) When deleting an unknown number of columns, it is best to start from the last column and to progress backward:
For (i = NCols, i>=1, i--, ....
3) You may want to simplify your delete line of code by simply using: dt << Delete Column (Column (i))

Best,
TS
Thierry R. Sornasse
gzmorgan0
Super User (Alumni)

Re: JSL to Delete Columns Based on Column Names

@user8421 ,

 

@Thierry_S provide you ith excellent suggestions.  Also look up the character function Starts With(ColNameList[i], "Raw")