Data visualization with SAS programming

SAS GCHART

Reply
Occasional Contributor
Posts: 13

SAS GCHART

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?

Super User
Posts: 17,829

Re: SAS GCHART

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?

Occasional Contributor
Posts: 13

Re: SAS GCHART

Right now, I have this:

For_SAS.jpg

 

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

Super User
Posts: 10,500

Re: SAS GCHART

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.

Occasional Contributor
Posts: 13

Re: SAS GCHART

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

Super User
Posts: 17,829

Re: SAS GCHART

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.

Occasional Contributor
Posts: 13

Re: SAS GCHART

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

SAS Super FREQ
Posts: 1,105

Re: SAS GCHART

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/

Occasional Contributor
Posts: 13

Re: SAS GCHART

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

Super User
Posts: 10,500

Re: SAS GCHART


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?

 

Occasional Contributor
Posts: 13

Re: SAS GCHART

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

Slide2.JPG

Slide1.JPG

Super User
Posts: 17,829

Re: SAS GCHART

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. 

PROC Star
Posts: 1,561

Re: SAS GCHART

[ Edited ]

[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

 

 

SAS Employee
Posts: 967

Re: SAS GCHART

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

 

 

Ask a Question
Discussion stats
  • 13 replies
  • 379 views
  • 0 likes
  • 6 in conversation