Share your ideas for the JMP Scripting Unsession at Discovery Summit by September 17th. We hope to see you there!
Choose Language Hide Translation Bar
Highlighted

How to calculate Day/Month

I have a data set with a time column covering 10 years of data. How can I calculate month/day (without year) from this column? I want to place this new variable on x axis and overlay my plot by year to look at the trend of my variable (ozone concentration) year-over-year. One idea is to use Day of Year, but I want to show the months on the x axis too which is not possible with Day of Year. Any suggestions?

4 REPLIES 4
Highlighted
txnelson
Super User

Re: How to calculate Day/Month

I would do it by creating 2 new columns;  Assuming your current date column is called :Date, I did the following

  1. Create a new column called Year, with the following formula
    Year(:Date);
  2. Create a new column called Month_Day.  All of the values will have the same year, to standardize the Month_Day.  
    DateMDY(month(:Date), Day(:Date), 2020);
    and apply this custom format to the new column
    monthList = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
    };
    monthList[Month( :value )] || "/" || Char( Day( :value ) );
    overlay.PNG
  3. Attached is the data table that created this graph, along with the script
Jim
Highlighted
shasheminassab
Level III

Re: How to calculate Day/Month

Thanks @txnelson for the advice. The only issue with this method is that I cannot easily control the min, max, and interval of the x axis since it not really a date format. 

Highlighted
txnelson
Super User

Re: How to calculate Day/Month

The column "Adjusted month_day" is a JMP Date column.  It is only displayed using a custom format.  Yes, if you want to go to the Axis setting for the X axis, you would have to enter the values in in the raw date value( the number of seconds since January 1st, 1904), but interactively, you can move, compress, expand the axis normally, and if you are setting the values in JSL, you can always use the Informat() function to set the min, max values in a user friendly structure

gb = Graph Builder(
	Variables( X( :Adjusted month_day ), Y( :Y ), Overlay( :Year ) ),
	Elements( Points( X, Y, Legend( 15 ) ), Smoother( X, Y, Legend( 16 ) ) )
);
report(gb)[AxisBox(1)] << min( informat("05/01/2020","m/d/y")) << inc( in weeks(1));

english.PNG

Jim
Highlighted

Re: How to calculate Day/Month

Wonderful!! Thanks.
Article Labels

    There are no labels assigned to this post.