BookmarkSubscribeRSS Feed
neilxu
Calcite | Level 5
I have a dataset like this:
green red
day1 4 5
day2 7 8
day3 1 2
....

I want to plot a vbar chart.
the x-axis is the day1, day2, ...
the y-axis is the number of green or red.

Is it possible to put green and red bars side by side on each day?

Thanks
7 REPLIES 7
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
With VBAR, consider GROUP= and SUBGROUP= options.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:
gchart vbar group subgroup site:sas.com
DanH_sas
SAS Super FREQ
What version of SAS are you using?
GraphGuy
Meteorite | Level 14
This should get you pointed in the right direction...


data foo;
input day colorvar $ 3-3 value;
datalines;
1 A 4
1 B 5
2 A 7
2 B 8
3 A 1
3 B 2
;
run;

pattern1 v=s c=green;
pattern2 v=s c=red;

axis1 label=none order=(0 to 10 by 2) minor=none offset=(0,0);
axis2 label=('Day') offset=(3,3);
axis3 label=none value=none;

legend1 label=(position=top 'Legend:') position=(right middle)
across=1 shape=bar(.15in,.15in) offset=(-5,0);

title1 "Here is your graph...";
proc gchart data=foo;
vbar colorvar / discrete type=sum sumvar=value
group=day subgroup=colorvar
space=0 raxis=axis1 gaxis=axis2 maxis=axis3 legend=legend1
autoref cref=graydd clipref
;
run;
neilxu
Calcite | Level 5
thank you Robert.

I was thinking about changing the dataset layout. It looks like I have to do this first then use vbar to plot.

thanks for the code, very very helpful.
neilxu
Calcite | Level 5
Currently the x-axis is day, can I sum the value in the same month and output, so the x-axis is month/year?

thanks I added midpoints "by month" and format days monyy. it looks like it works.


Message was edited by: neilxu
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Use the INTNX function in a DATA step to derive a "month start date" and then apply a SAS output FORMAT to display month/year as desired on the X-axis.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search arguments, this topic / post:

intnx function site:sas.com

date format month year site:sas.com
neilxu
Calcite | Level 5
Thanks for your help.

SAS Innovate 2025: Register Today!

 

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1428 views
  • 0 likes
  • 4 in conversation