cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
fionaweston
Level III

How do I script to change the name of my columns, presently dates, to just the day?

I  want to change just the numeric continuous columns in my sheet which are presently full dates and are in order from 1st to 31st to just the day 

ex 03/01/2020 to 1

03/02/2020 to 2

 

fionaweston_0-1618864273078.png

I would also like to add a column to my sheet with the Abbv Name of the Month.

 

Thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How do I script to change the name of my columns, presently dates, to just the day?

Here is how I would solve your request

Names Default To Here( 1 );
dt = Current Data Table();

theMonth=.;
For( i = 1, i <= N Cols( dt ), i++,
	If( Substr( Column( dt, i ) << get name, 1, 2 ) == "N(",
		If( isMissing(theMonth) == 1,
			theMonth = Month( Informat( Word( 2, Column( dt, i ) << get name, "()" ), "m/d/y" ) );
		);
		Column( dt, i ) << set name(
			Char( Day( Informat( Word( 2, Column( dt, i ) << get name, "()" ), "m/d/y" ) ) )
		)
	)
);

monthList = {"Jan","Feb","Mar","Apr","May","Jun",
	"Jul","Aug","Sep","Oct","Nov","Dec"
};
dt << New Column( monthList[theMonth]);
Jim

View solution in original post

3 REPLIES 3
Georg
Level VII

Re: How do I script to change the name of my columns, presently dates, to just the day?

You could do it like this:

 

Names Default To Here( 1 );

dt = New Table( "Dates",
	New Column( "date", "Numeric", "Continuous", Format( "Date Abbrev", 20 ), set values( Date DMY( Index( 1, 31 ), 3, 2020 ) ) )
);
Wait( 3 );

dt << New Column( "Day", Formula( Day( :date ) ) );
dt:date << hide();
dt << New Column( "Month",
	Formula(
		Match( Month( :date ),
			1, "Jan",
			2, "Feb",
			3, "Mar",
			4, "Apr",
			5, "May",
			6, "Jun",
			7, "Jul",
			8, "Aug",
			9, "Sep",
			10, "Oct",
			11, "Nov",
			12, "Dec"
		)
	)
);
Georg
txnelson
Super User

Re: How do I script to change the name of my columns, presently dates, to just the day?

Here is how I would solve your request

Names Default To Here( 1 );
dt = Current Data Table();

theMonth=.;
For( i = 1, i <= N Cols( dt ), i++,
	If( Substr( Column( dt, i ) << get name, 1, 2 ) == "N(",
		If( isMissing(theMonth) == 1,
			theMonth = Month( Informat( Word( 2, Column( dt, i ) << get name, "()" ), "m/d/y" ) );
		);
		Column( dt, i ) << set name(
			Char( Day( Informat( Word( 2, Column( dt, i ) << get name, "()" ), "m/d/y" ) ) )
		)
	)
);

monthList = {"Jan","Feb","Mar","Apr","May","Jun",
	"Jul","Aug","Sep","Oct","Nov","Dec"
};
dt << New Column( monthList[theMonth]);
Jim
fionaweston
Level III

Re: How do I script to change the name of my columns, presently dates, to just the day?

Thanks Jim, this is great.