cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Don’t miss your chance to experience Discovery Summit Europe at our best available rate! Early bird registration through 31 Oct.
  • Image to Table JMP extension imports single or batch images as data tables. Useful to extract curves from pictures or convert image data to curve data to use in analyses like Functional Data Explorer. Download and install the extension.

Discussions

Solve problems, and share tips and tricks with other JMP users.
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.

Recommended Articles