Subscribe Bookmark RSS Feed

Converting date categories to a continual date axis

rrimler

Community Trekker

Joined:

Sep 26, 2013

Hi all,

I measured the growth of a group of animals roughly once a month for three months, and then let two months go by before I measured them a final time. I would like to graph the average growth over time. To do this, I will need to include a gap along the x-axis to represent the two month period when I didn't record growth. In other words, my x coordinates are January 9, 10, 11; February 11, 12, 13; March 29, 30; April 11, 12; and July 9, 10. (It took me several days to measure all the individuals in the population each time, so each "monthly" measurement actually consists of two or three days.) How do I get the program to recognize these as dates and space them accordingly along the x-axis when I construct a graph? Alternatively, how do I change the dates to Julian day? I'd rather display the actual dates with tick marks representing every day, or every 10 days or whatever, that provide the correct spacing in between the dates.

Thanks very much for your help.

9 REPLIES
bruno_sas

Staff

Joined:

Jun 23, 2011

hi

Proc SGPLOT supports time axis, see sample code below.

data have;
  infile cards dlm=",";
 
input
    date :
date9.
  ;
  format date date9.;
  population = ceil( rand(
"uniform") * 25) + 20;
cards;
09jan2013
10jan2013
11jan2013
11feb2013
12feb2013
13feb2013
29mar2013
30mar2013
11apr2013
12apr2013
09jul2013
10jul2013
;

proc sgplot data=have;
  series x=date y=population / markers;
 
yaxis min=0;
 
xaxis type=time interval=week grid;
run;
ms

Super User

Joined:

Jun 23, 2011

Assuming you use JMP, you need to use a continuous, date-formatted column as x-variable.

One way to convert your date strings into date-values is to use a column formula. In the jsl example below the strings are found in column "x"  and the formula in column "Date" turn "x" into the corresponding date (here based on the first day of the measurement interval).

dt = New Table( "example",

  Add Rows( 4 ),

  New Column( "x",

  Character,

  Nominal,

  Set Values( {"January 9, 10, 11", "February 11, 12, 13", "April 11, 12", "July 9, 10"} )

  )

);

dt << New Column( "Date",

  Numeric,

  Continuous,

  Format( "ddMonyyyy", 12 ),

  Input Format( "ddMonyyyy" ),

  formula( Parse Date( Words( :x, ", " )[2] || Left( :x, 3 ) || "2013", "ddMonyyyy" ) )

);

rrimler

Community Trekker

Joined:

Sep 26, 2013

Thank you both for your replies. I am new to JMP and don't have experience with programming language. Could you walk me through these formulas? I guess my first question is (and I'm a little embarrassed to ask)-- where do I write all this stuff? Under column formula? Also, what does dt mean?

pmroz

Super User

Joined:

Jun 23, 2011

Hi rrimler,

Suppose your data looks like this.  Notice that the Measurement Date column is of text type, and the dates are in the form ddMonYYYY.

4254_Growth Table.png

Right click on the empty column header next to the word "Growth" and select "New Column".  Call this column Measurement Dt

Set the format of the data to Date > ddMonYYYY

Click on Column Properties > Formula.

4255_New Column.png

Click on the Edit Formula button

Double click inside the red box that says no formula and enter the following text: informat(:Measurement Date, "ddMonYYYY")

Click OK and the OK again.

Now your dataset has a numeric column that shows the date you entered in the first column.

4256_Final Growth Table.png

Click on Graph > Graph Builder.  Drag Measurement Dt to the X axis, and Growth to the Y axis. 

4257_Growth Graph.png

rrimler

Community Trekker

Joined:

Sep 26, 2013

Thank you! It worked. Although when I try to make a chart instead of using graph builder, it doesn't work (it graphs the dates as categories instead of as a continuous variable.) If you have any advice about how to fix the problem in "chart", I'd appreciate it. However it works great in graph builder and that is a huge step forward for me!

mpb

Super User

Joined:

Jun 23, 2011

Have you tried Overlay Plot?

rrimler

Community Trekker

Joined:

Sep 26, 2013

Well, the thing is that I want to graph the mean growth including error bars, and as far as I can figure out the only way to do that is select Graph--> Chart. That dialogue box gives the option of running the "statistic" of the column. "Graph Builder" and "Overlay Plot" don't give you the option of running a statistic. Is there something I'm missing? 

ms

Super User

Joined:

Jun 23, 2011

Yes, a column formula is added by adding the property Formula to a column, as PMroz shows nicely. In my example, the formula is just the expression within Formula().  You do not need to understand the rest of the code. The entire code was for demonstration only, and was supposed to make an example table and add a column with that particular formula. Try it! Copy the code to a JMP script window and hit run. You can copy the formula from the example table to your own data table if it seems to work the way you want.

Regarding dt, it is just a variable for for the data table.

Bruno's code is for SAS and will not work in JMP.

rrimler

Community Trekker

Joined:

Sep 26, 2013

Thanks very much. Very helpful!