Help using Base SAS procedures

Gplot : Date on X-axis not showing correctly

Accepted Solution Solved
Reply
New Contributor haw
New Contributor
Posts: 2
Accepted Solution

Gplot : Date on X-axis not showing correctly

I'm having some troubles with the x-axis when using proc gplot.

 

The X-axis should display the values:

 

31OCT2014   30NOV2014   31DEC2014 ... 

 

but this is not the case. Instead the values are shifted one single day, which means

that the values shown on the x-axis in the plot are:

 

01NOV2014   01DEC2014   01JAN2015

 

Does anyone know why this happens? Here's and example:

 


data test;
     input month value;
     datalines;
20027 89
20057 139
20088 213
20119 131
20147 371
20178 418
20208 790
20239 532
run;

 

proc gplot data = test;

        plot value * month ;
        format month date9. ;
run;
quit;

 

An additional annoying this is that not only has the x-values shifted one single day, an additional tick mark (01OCT2014) appears in which no corresponding y-value exists.

 

 


Accepted Solutions
Solution
‎01-18-2016 04:16 AM
Super User
Super User
Posts: 7,397

Re: Gplot : Date on X-axis not showing correctly

It hasn't moved your data.  It is setting the tick values up in what it can logically assign as a logical order.  So your first data item, 31oct, is between 01oct and 01nov.  As the logical sequence chosen is 01 of each month, it need to include both of those to be able to plot 32oct which is just off to the left of 01nov.  To get round this you need to tell the system what your axis ticks should be, don't let the system guess for you.  I don't use the old gplot software, so can't remember the syntax, but if you move to sgplot or graph template it is along the lines of:

 xaxis / values=("31oct2014"d "30nov2014"d etc.);

 

 

View solution in original post


All Replies
Solution
‎01-18-2016 04:16 AM
Super User
Super User
Posts: 7,397

Re: Gplot : Date on X-axis not showing correctly

It hasn't moved your data.  It is setting the tick values up in what it can logically assign as a logical order.  So your first data item, 31oct, is between 01oct and 01nov.  As the logical sequence chosen is 01 of each month, it need to include both of those to be able to plot 32oct which is just off to the left of 01nov.  To get round this you need to tell the system what your axis ticks should be, don't let the system guess for you.  I don't use the old gplot software, so can't remember the syntax, but if you move to sgplot or graph template it is along the lines of:

 xaxis / values=("31oct2014"d "30nov2014"d etc.);

 

 

New Contributor haw
New Contributor
Posts: 2

Re: Gplot : Date on X-axis not showing correctly

Thank you - all of you for a great and quick response.

 

Your help was strongly appreciated!

Super User
Posts: 17,784

Re: Gplot : Date on X-axis not showing correctly

proc sgplot data = test;
scatter y= value x= month ;
        format month date9. ; 
xaxis values=("31oct2014"d "30nov2014"d "01Jan2015"d "28FEB2015"d "31MAR2015"d "30APR2015"d "31MAY2015"d );
run;
quit;

Here's an example, it's close but not exact, but you can play around with the axis statement. 

 

 

Super User
Posts: 10,483

Re: Gplot : Date on X-axis not showing correctly

GPLOT, unless told otherwise with an AXIS statement, will default to guessing the "best" display for values. If the variable has a DATE related format then it will make guesses based on dates. If your data had spanned enough years you might only see ticks for January or January and July.

 

Another way would be to try using a different format such as MONYY7. The ticks will still actually appear on the graph at the first of the month the the "annoying" day of month won't display.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 548 views
  • 1 like
  • 4 in conversation