BookmarkSubscribeRSS Feed
mbsuther
Calcite | Level 5

I have to chart 5 years of usage data, one bar for each month. A request has come to show all 5 years worth of bars, but only have quarterly values appear on the horizontal axis. Is there an easy way to do this?

13 REPLIES 13
Reeza
Super User

What do you mean by:

but only have quarterly values appear on the horizontal axis

 

Are you looking to change the aggregation from monthly to quarterly or to just change the labels on the axes?

mbsuther
Calcite | Level 5

Right now, I have this:

For_SAS.jpg

 

The request is to replace all the mm/yyyy with one mmyyyy value for each quarter.

ballardw
Super User

GCHART AXIS statement controls the number of tickmarks and the values displayed. Likely to get this to work you will need DATE values for your x axis. Is that the case?

And due to interaction it might help to show your current GCHART code.

 

Or consider changing to Proc SGPLOT. If you consider this option we need to know which version of SAS you are running as there have been many changes to options in the past few releases.

mbsuther
Calcite | Level 5

see the sample JPG I posted in the response to the previous response

Reeza
Super User

Change your aggregations to quarterly. If you're doing aggregations in the GCHART (can't even remember if that's possible) format your date with a quarter format and see if that changes things.

 

If you're aggregating your data outside of the GCHART proc then change it there.

 

Also, consider switching to SGPLOT if that's an option. Much better quality graphics.

mbsuther
Calcite | Level 5

I will give it a try. I will also look at the SGPLOT options.

Jay54
Meteorite | Level 14

As Ballardw asked earlier, what is the release of SAS (with maintenance level) are you using.  This is important.  With SAS 9.40M3, you can make bar charts on interval or time axis, that may allow you more flexibility. 

See:  http://blogs.sas.com/content/graphicallyspeaking/2015/08/12/bar-chart-on-interval-axis-sas-9-40m3/

mbsuther
Calcite | Level 5

we are using 9.4M3. Will look at your blog. Thanks.

ballardw
Super User

@mbsuther wrote:

see the sample JPG I posted in the response to the previous response


I don't see any code.

 

How you are summarizing data affects the options available.

What is your current raxis definition? Also you did not show whether your date varaible is actually a date or not. If your variable is not a date then the syntax for an AXIS statement, or the equivalent for SGPLOT is nastier.

 

And is the desire to show "one value per quarter" or "one tick mark per quarter with the month data as previous"? And what format should that tick value show: 01/2012,   Jan 2012, 2012 Q1 or something else? Should the position be at the first, middle or last of a calendar quarter?

 

mbsuther
Calcite | Level 5

I did not make myself very clear. I need to use PROC GCHART. I want to go to/from:

Slide2.JPG

Slide1.JPG

Reeza
Super User

As someone else already mentioned look at the AXIS statement to control the tick values. Post your code, ideally with some sample data, if you need help with the code. 

ChrisNZ
Tourmaline | Level 20

[Edited: Sorry, unsure how I got to open this old question 😕 ].

 

Like this? 

 


goptions xpixels=640 ypixels=200;

data PLOT; 
  format DATE monyy.;
  do DATE='01jan2011'd to '01jan2015'd by 31;
    output;
  end;
run;

proc gchart;
   vbar DATE /discrete ;
   run;
quit;

data _null_;
  set PLOT end=LASTOBS;
  if _N_=1 then call execute('axis1 value=(');
  call execute(quote(ifc(month(DATE) in(1,4,7,10),put(DATE,monyy.),' ')));
  if LASTOBS then call execute(');');
run;

proc gchart;
   vbar DATE /discrete maxis=axis1;
   run;
quit;

  

aaa1.PNG

 

 

GraphGuy
Meteorite | Level 14

One thing I would recommend for this graph is using a 'grouped bar chart' (grouping by year).

That will clean up the axis a lot (rather than repeating the year in the label of each bar).

 

Here's a simple example that might be helpful:

 

 

data mydata; set sashelp.stocks (where=(stock='IBM' and date>='01jan2003'd));
year=.; year=year(date);
run;

goptions gunit=pct htitle=4 htext=2.25;

axis1 value=(angle=0) label=none;
axis2 label=none;
axis3 label=none minor=none;

pattern1 v=s c=dodgerblue;

title1 "Stock price for IBM, by month";
proc gchart data=mydata;
format date month.;
format close dollar8.0;
vbar date / discrete type=sum sumvar=close
group=year nozero space=0 maxis=axis1 gaxis=axis2 raxis=axis3;
run;

 

by_year.png

 

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 13 replies
  • 2781 views
  • 0 likes
  • 6 in conversation