Saving report output to a data table often creates long column names that become cumbersome in subsequent analyses. This is a stupid little script to replace/remove text from the names of selected columns.
Usage: select the columns you want to modify, run the script, enter the text that needs to be changed (including spaces), and then enter the text to change it to (again including spaces, leave blank to replace with nothing).
Obviously if there are no open data tables, the script does nothing. If there are no columns selected, i.e.there aren't any columns identified as needing change, the script currently does nothing, though a prompt to select columns could be added.
Update: The first selected column name is included in the text box to make it easier to indicate the text to be found
thank you for posting ... is their a way to make this an add-in?
Done.
Thanks for your sharing.
But this great add-in cannot be used on JMP16.
It show error message: deleted object reference:editbox<<get next in access or evaluation of 'Glue'
Is there any solution for it?
Sorry it took so long to respond, I forgot I posted this here. Yes it can be fixed. - DONE
It may take a bit before the update is posted.
Here is the updated script (the only change was to add << Return Result, so the Text Box would return what was entered (not sure why it worked before):
//!
// Initialize
Names Default to Here( 1 );
Clear Log();
dt = Current Data Table( );
// Stop the script if no open data tables
If( Is Empty( dt ), Stop());
cols = dt << Get Selected Columns( );
// Stop the script if no columns selected
If( N Items( cols ) == 0, Stop());
// Prompt user for text to remove
eBox1 = New Window(
"Find",
<< Modal,
<< Return Result,
Text Box(
"What text should be removed from the column names
(including spaces, i.e. delete the text you want to keep)?",
Justify Text ("Center"),
Set Width(500)
),
Spacer Box( Size( 12.5, 12.5 ) ),
editBox = Text Edit Box(cols[1] << Get Name()),
editBox << Set Width(500),
Spacer Box( Size( 12.5, 12.5 ) ),
H List Box( Button Box( "OK",
remove this = editBox << Get Text;
// Stop the script if the user doesn't enter any text
If( remove this == "", Stop())
),
Button Box( "Cancel" ),
<< Horizontal Alignment( "Center" )
)
);
// Stop the script if the user hits the cancel button
If( eBox1["Button"] == -1, Print("Canceled"); Stop());
// Prompt user for text to replace
eBox2 = New Window(
"Replace With",
<< Modal,
<< Return Result,
Text Box(
"What should the text be replaced with
(including spaces, or leave blank)?",
Justify Text ("Center"),
Set Width(300)
),
Spacer Box( Size( 12.5, 12.5 ) ),
editBox2 = Text Edit Box(),
editBox2 << Set Width(300),
Spacer Box( Size( 12.5, 12.5 ) ),
H List Box( Button Box( "OK",
replace with = editBox2 << Get Text
),
Button Box( "Cancel" ),
<< Horizontal Alignment( "Center" )
)
);
// Stop the script if the user hits the cancel button
If( eBox2["Button"] == -1, Print("Cancled"); Stop());
// Loop through the columns adding the tag to the end of the existing name
For( i = 1, i <= N Items( cols ), i++,
cols[ i ] << set name( munger(cols[ i ] << get name, 1, remove this, replace with))
); // Next column
// End