Data visualization with SAS programming

Proc sgplot - Easy way to format dates on xaxis to show only month, no year?

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

Proc sgplot - Easy way to format dates on xaxis to show only month, no year?

I'm overlaying cumulative distributions from multiple years in one plot, plotting the cumulative percentage by date. I had to convert all dates to the same year to get them to all plot on the same xaxis.  The xaxis tick marks are months, but SAS insists on showing the year on this axis. The date values are formatted as 'MMDDYY4.' but SAS overrides the formats and uses auto date formats.

 

Is there any way to format the x axis to display only the month?

 

Code:

proc sgplot data=CumulH;
    series x=dummydate y=cum_pct/group = year;
    xaxis label='Date' max = '01DEC2000'd;
run;


CumulHplot.png

Accepted Solutions
Solution
‎11-28-2016 12:51 PM
SAS Super FREQ
Posts: 925

Re: Proc sgplot - Easy way to format dates on xaxis to show only month, no year?

Since you have SAS 9.3, use TICKVALUEFORMAT instead of VALUESFORMAT. VALUESFORMAT is correct name of the option for SAS 9.4 and beyond, but TICKVALUEFORMAT will continue to work. 

View solution in original post


All Replies
Super User
Posts: 19,038

Re: Proc sgplot - Easy way to format dates on xaxis to show only month, no year?

Try using MONNAME3 format to show just the month?

New Contributor
Posts: 4

Re: Proc sgplot - Easy way to format dates on xaxis to show only month, no year?

Thanks, tried formatting dummydate as MONNAME3., and even though the data appear in that format in the data file the plot still ignores it. 

 

The log shows:

NOTE: The column format MONNAME3 is replaced by an auto-generated format on the axis.

 

I should have mentioned in the original post that I am using SAS 9.3 TS 1M0.

Respected Advisor
Posts: 4,804

Re: Proc sgplot - Easy way to format dates on xaxis to show only month, no year?

Use

 

xaxis label='Date' max = '01DEC2000'd valuesformat=mmddyy4.;

to override the automatic date format.

PG
New Contributor
Posts: 4

Re: Proc sgplot - Easy way to format dates on xaxis to show only month, no year?

Thanks, interesting idea. I was looking for a way to override the default format. I should have mentioned in the original post that I'm using SAS 9.3.  The valuesformat option is not listed for the xaxis statement in the SAS 9.3 ODS Graphics Procedures Guide (Second Edition). Is that available in SAS 9.4?   I tried it anyway, and this was the log response:

 

627    xaxis label='Date' max = '01DEC2000'd valuesformat=mmddyy4.;
                                             ------------ --------
                                             1            79
                                                          76
WARNING 1-322: Assuming the symbol VALUES was misspelled as valuesformat.
ERROR 79-322: Expecting a (.
ERROR 76-322: Syntax error, statement will be ignored.
628  run;

Solution
‎11-28-2016 12:51 PM
SAS Super FREQ
Posts: 925

Re: Proc sgplot - Easy way to format dates on xaxis to show only month, no year?

Since you have SAS 9.3, use TICKVALUEFORMAT instead of VALUESFORMAT. VALUESFORMAT is correct name of the option for SAS 9.4 and beyond, but TICKVALUEFORMAT will continue to work. 

New Contributor
Posts: 4

Re: Proc sgplot - Easy way to format dates on xaxis to show only month, no year?

Perfect, thanks! I don't know why I didn't see that sooner.

☑ This topic is solved.

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

Discussion stats
  • 6 replies
  • 1119 views
  • 0 likes
  • 4 in conversation