cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

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