Data visualization with SAS programming

vbar side by side

Reply
Contributor
Posts: 32

vbar side by side

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
Super Contributor
Super Contributor
Posts: 3,174

Re: vbar side by side

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
SAS Super FREQ
Posts: 864

Re: vbar side by side

What version of SAS are you using?
SAS Employee
Posts: 963

Re: vbar side by side

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;
Contributor
Posts: 32

Re: vbar side by side

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.
Contributor
Posts: 32

Re: vbar side by side

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
Super Contributor
Super Contributor
Posts: 3,174

Re: vbar side by side

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
Contributor
Posts: 32

Re: vbar side by side

Thanks for your help.
Post a Question
Discussion Stats
  • 7 replies
  • 199 views
  • 0 likes
  • 4 in conversation