BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Wang_Yajun
Obsidian | Level 7

Hi,

 

I want to plot a graph to compare the real sales and planned sales over the years, the original dataset is  

YearDesiredReal
2006987689
2007588827
2008313150
2009716349
2010575376
2011686979
2012189288
2013509112
2014741828
2015309967

I wonder if there is any possible ways in SAS to get the same effects as in the following graph.

 

Multiple Bar charts side by side.png

 

 


Multiple Bar charts side by side.png
1 ACCEPTED SOLUTION

Accepted Solutions
DanH_sas
SAS Super FREQ

Here you go:

 

data sales;
input Year Desired Real;
cards;
2006 987 689
2007 588 827
2008 313 150
2009 716 349
2010 575 376
2011 686 979
2012 189 288
2013 509 112
2014 741 828
2015 309 967
;
run;

proc sgplot data=sales;
vbarparm category=Year response=Desired / discreteoffset=-0.17 barwidth=0.3;
vbarparm category=Year response=Real / discreteoffset=0.17 barwidth=0.3;
run;

View solution in original post

6 REPLIES 6
jimhorne
Obsidian | Level 7

You can use PROC SGPANEL after you play with your data a little bit - that will give you graphs like you want

Rick_SAS
SAS Super FREQ

of course. Transpose the data from "wide form" to "long form" and use PROC SGPLOT like this:

 

data Have;
input Year Desired Real ;
datalines;
2006 987 689 
2007 588 827 
2008 313 150 
2009 716 349 
2010 575 376 
2011 686 979 
2012 189 288 
2013 509 112 
2014 741 828 
2015 309 967 
;

data Want;
set Have;
Group = "Desired"; Value = Desired; output;
Group = "Real   "; Value = Real; output;
drop Desired Real;
run;

proc sgplot data=Want;
vbar Year / response=Value group=Group groupdisplay=cluster;
run;
Wang_Yajun
Obsidian | Level 7

Hi, Rick

 

Thanks for your reply, it really works. I really appreciate it , but I don't know how to accept both two replies as solutions.

Rick_SAS
SAS Super FREQ

You can only accept one solution, so give "Likes" to other helpful coments and post a comment (which you have already done!) that indicates that another answer also works.   Many times in SAS there are three or four ways to solve the same problem.

 

I'm glad your problem is resolved.

Wang_Yajun
Obsidian | Level 7
Hi, Rick

Under SAS 9.2, there is no groupdisplay option in the VBAR statement, so is there another way to get the desired graph under SAS 9.2? Thanks a lot.
DanH_sas
SAS Super FREQ

Here you go:

 

data sales;
input Year Desired Real;
cards;
2006 987 689
2007 588 827
2008 313 150
2009 716 349
2010 575 376
2011 686 979
2012 189 288
2013 509 112
2014 741 828
2015 309 967
;
run;

proc sgplot data=sales;
vbarparm category=Year response=Desired / discreteoffset=-0.17 barwidth=0.3;
vbarparm category=Year response=Real / discreteoffset=0.17 barwidth=0.3;
run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 6 replies
  • 10916 views
  • 3 likes
  • 4 in conversation