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
user8421
Level I

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
Highlighted
Thierry_S
Level VI

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

Highlighted
gzmorgan0
Super User

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
Highlighted
Thierry_S
Level VI

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

Highlighted
gzmorgan0
Super User

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

Article Labels