cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
ShahirahLoqman
Level II

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?

col properties.JPG

 

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!

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

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 )
	);
);
Jim

View solution in original post

7 REPLIES 7
gzmorgan0
Super User (Alumni)

Re: Script to Change Column Names Using Column Properties

@ShahirahLoqman,

 

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) );
);
txnelson
Super User

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 )
	);
);
Jim
ShahirahLoqman
Level II

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.

txnelson
Super User

Re: Script to Change Column Names Using Column Properties

Can you upload your data table, and I will look into the issue further
Jim
ShahirahLoqman
Level II

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?

txnelson
Super User

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.

Jim
ShahirahLoqman
Level II

Re: Script to Change Column Names Using Column Properties

Jim, the script works now! just had to tweak Get Properties to Get Property. thanks so much