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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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