Exploring, modeling, predicting and reporting with SAS Visual Analytics and SAS Visual Statistics

Combining two bar charts

Reply
Regular Contributor
Posts: 181

Combining two bar charts

[ Edited ]

I am new to SAS VA. I am trying to create a bar chart showing comparison of two groups. Data for the 2 groups are in separate files (data sources). I want the chart to be displayed as shown below. Since data for the 2 groups are in separate data sources, i am able to create two bar charts but unable to combine them in a single bar chart showing 2 bars for each of the groups.

SAS VA.png

 

Any help would be highly appreciated. Thanks!

Regular Contributor
Posts: 150

Re: Combining two bar charts

I'm new, as well, so I'm taking this as a challenge: If you reorganize your data a little, this will give the closest I can get to your picture. The bars are next to each other.

data example;
   infile datalines delimiter=',';
   input turnover $ value group;
   datalines;                      
0-5,45,1
0-5,44,2
5-10,17,1
5-10,20,2
10-15,38,1
10-15,36,2
;

/* general routine:
    http://blogs.sas.com/content/sascom/2011/08/22/how-to-make-a-cluster-grouped-bar-chart-graph-using-sas-sg-procedures/ */
proc sgplot data=example;
  vbar turnover / response=value group=group stat=sum nostatlabel
         groupdisplay=cluster barwidth=0.9 transparency=0;
  xaxis display=(nolabel);
  yaxis grid;
  run;

Otherwise, a different method will get the bars on top of each other. you can play around with barwidth and transparency to see what you like:


data example;
   infile datalines delimiter=',';
   input turnover $ group1 group2;
   datalines;                      
0-5,45,44
5-10,17,20
10-15,38,36
;

/* general routine:
    http://blogs.sas.com/content/sascom/2011/08/22/how-to-make-a-cluster-grouped-bar-chart-graph-using-sas-sg-procedures/ */
proc sgplot data=example;
  vbar turnover / response=group1 stat=sum nostatlabel
         groupdisplay=cluster barwidth=0.5 transparency=0.2;
  vbar turnover / response=group2 stat=sum nostatlabel
         groupdisplay=cluster barwidth=0.7 transparency=0.2;
  xaxis display=(nolabel);
  yaxis grid;
  run;
Regular Contributor
Posts: 181

Re: Combining two bar charts

My question is how to do this in SAS Visual Analytics software rather than base SAS. Thanks!
Super User
Posts: 1,205

Re: Combining two bar charts

As you've discovered the data needs to be in the same data source for a single visualization/report object. When you are working with a visualization/report object only 1 data source can be selected and therefore you will need to bring your groups together in the same data source if you want a clustered bar chart.

Grand Advisor
Posts: 9,713

Re: Combining two bar charts

Note that your Excel example does not have the data in two different workbooks.

Post a Question
Discussion Stats
  • 4 replies
  • 228 views
  • 0 likes
  • 4 in conversation