- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Script to Change Column Names Using Column Properties
Hi, I am trying to script for my column names to be replaced with a specific column property called "Description". How do I extract whatever is stored under description and use that as my new column name?
I tried running my own script but it didn't really work out
dt = Current Data Table();
For( i = i, i <= N Cols( dt ), i++,
newname = (Column( dt, i ) << Get Column Properties("Description"));
Column( dt, i ) << Set Name(newname);
);
Appreciate the help!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Script to Change Column Names Using Column Properties
Great attempt......close but just a few, mainly syntax issues. You need to start looking up examples of the functions you are attempting to use, in the Scripting Index.
// Isolate the code to only impacting this script
// and not all scripts
Names Default To Here( 1 );
dt = Current Data Table();
// i=1 rather than i=i
For( i = 1, i <= N Cols( dt ), i++,
// Get Properties rather than Get Column Properties
newname = Column( dt, i ) << Get Properties( "Description" );
// If there isn't a Description Column Property you do not
// want to change the column name
If( Is String( newname ),
Column( dt, i ) << Set Name( newname )
);
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Script to Change Column Names Using Column Properties
See script below. The syntax is Get Property( "name" )
Names Default to Here(1);
dt = New Table( "TestIt",
Add Rows( 5 ),
New Column( "A",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Property( "Description", "A description" ),
Set Values( [1, 2, 3, 4, 5] )
),
New Column( "B",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Property( "Description", "Heck if I know" ),
Set Values( [275, 300, 295, 280, 385] )
)
);
For(i=1, i<=ncol(dt), i++,
_xx = column(dt,i) << get property("Description");
show(_xx);
if( IsString(_xx), column(dt,i) << set name(_xx) );
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Script to Change Column Names Using Column Properties
Great attempt......close but just a few, mainly syntax issues. You need to start looking up examples of the functions you are attempting to use, in the Scripting Index.
// Isolate the code to only impacting this script
// and not all scripts
Names Default To Here( 1 );
dt = Current Data Table();
// i=1 rather than i=i
For( i = 1, i <= N Cols( dt ), i++,
// Get Properties rather than Get Column Properties
newname = Column( dt, i ) << Get Properties( "Description" );
// If there isn't a Description Column Property you do not
// want to change the column name
If( Is String( newname ),
Column( dt, i ) << Set Name( newname )
);
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Script to Change Column Names Using Column Properties
Thanks Jim! Unfortunately it's still not working even with the tweaks you suggested. I am not sure if it is my file. I tried using the Debug Script option but it crashed on me. I tried it on both JMP 14.1 and 15.0 and both could not execute the Debug Script.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Script to Change Column Names Using Column Properties
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Script to Change Column Names Using Column Properties
Jim, I don't think I can upload as it is proprietary company data with 170k rows of information.
Do you have any suggestions on what I should check in my data table?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Script to Change Column Names Using Column Properties
You should be able to upload the data table, if you delete all of the rows of data. What you need done does not require any rows of data.
Even without using the debugger, you can step through lines of code. Just put a
throw();
in your code to stop execution at the point where you are having an issue. You can the highlight statement by statement and run each individual line. The by hovering over the variables of interest, you can see what values they have.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content