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

Hi everybody,

I am producing some Vbars with Gchart procedure, using subgroup option,it is working with no problem. Say I have 3 subgroups with 3 corresponding colors, the values for each subgroup are in black color, ana I want that for the BLUE subgroup its value be in white color , and black for the two other subgroups is this possible?

and I want the values be inside the subgroups bars, but for the Upper subgroup i Want it on the BAR.

Thanks Smiley Wink

1 ACCEPTED SOLUTION

Accepted Solutions
GraphGuy
Meteorite | Level 14

Sure!

Whereas in a typical annotate data set for most procs (such as gplot and gmap), you assign Y and X variables.

For a gchart vbar, you assign a Y and Midpoint variable.

And for a subgrouped vbar, you assign a Subgroup and a Midpoint (to place the annotated text in the subgroups).

Here is an example that demonstrates annotating colored text in vbar subgroups, and controlling the color based on the subgroup value:

http://robslink.com/SAS/democd38/best_beer.htm

http://robslink.com/SAS/democd38/best_beer_info.htm

Specifically, here's how I created the annotate data set:

data anno_text; set mydata;

length function color $8;

xsys='2'; ysys='2'; when='a';

midpoint=data_order;

subgroup=medal;

function='label';

position='e';

text=trim(left(count));

if medal=1 then color='yellow';

else if medal=2 then color='black';

else if medal=3 then color='brown';

else color='pink';

run;

And here's a summary of the important parts of the gchart code:

proc gchart data=mydata;

vbar data_order / discrete

type=sum sumvar=count subgroup=medal

anno=anno_text;

run;

View solution in original post

12 REPLIES 12
GraphGuy
Meteorite | Level 14

For gchart vbar, you can specify colors for each subgroup, using pattern statements.

The colors will be assigned to the subgroups/bars in alphabetic order.

Here is an example:

pattern1 v=solid color=black;

pattern2 v=solid color=blue;

pattern3 v=solid color=black;

proc gchart data=sashelp.stocks;

vbar stock / type=mean sumvar=close subgroup=stock;

run;

kmel56
Calcite | Level 5

Hi Robert thank for you answer.

Maybe I wasn't so clear. My question wasn't about colors of subgroups( i have no problem with that) but I was meaning the values of each subgroup, say subgroup 1's value is 10, 2: 1 and 3: 15, what I want is that Value 10 for my first subgroup will be in WHITE color , and for the two other values Black color.

Thanks again

GraphGuy
Meteorite | Level 14

I guess you'll need to provide us with an example Smiley Happy

kmel56
Calcite | Level 5

subgroup.bmp

So this was done on EXCEL, I want the same thing on SAS, so you see for BLUE Subgroup the values are in WHITE and for the last Subgroup"Cyan Blue" one the value is on the BAR. How can I do that please Smiley Happy

GraphGuy
Meteorite | Level 14

Ahh - you mean the text labels in the bar subgroups!

I think the only way to have different colors for different ones is to annotate the labels, and assign the desired color in your annotate data set.

kmel56
Calcite | Level 5

Oh Okey, and can you give me a small example to do this with subgroups, I've never done it with subgroups:smileyplain:

GraphGuy
Meteorite | Level 14

Sure!

Whereas in a typical annotate data set for most procs (such as gplot and gmap), you assign Y and X variables.

For a gchart vbar, you assign a Y and Midpoint variable.

And for a subgrouped vbar, you assign a Subgroup and a Midpoint (to place the annotated text in the subgroups).

Here is an example that demonstrates annotating colored text in vbar subgroups, and controlling the color based on the subgroup value:

http://robslink.com/SAS/democd38/best_beer.htm

http://robslink.com/SAS/democd38/best_beer_info.htm

Specifically, here's how I created the annotate data set:

data anno_text; set mydata;

length function color $8;

xsys='2'; ysys='2'; when='a';

midpoint=data_order;

subgroup=medal;

function='label';

position='e';

text=trim(left(count));

if medal=1 then color='yellow';

else if medal=2 then color='black';

else if medal=3 then color='brown';

else color='pink';

run;

And here's a summary of the important parts of the gchart code:

proc gchart data=mydata;

vbar data_order / discrete

type=sum sumvar=count subgroup=medal

anno=anno_text;

run;

kmel56
Calcite | Level 5

WOW I wasn't beleive that superman exists, thanks a lot

kmel56
Calcite | Level 5

Hi Robert,

can I ask you an other small question. In fact I want that the text label for the upper subgroupe (Cyan blue and mybe another one, if the cyanblue subgroup have 0 observations) be ON the BAR and not inside, like in the excel example.

I have tried this but doesn't work :

data anno_text; set cross1;

length function color $8;

xsys='2'; ysys='2'; when='a';

midpoint=nat;

subgroup=grave;

function='label';

position='e';

text=trim(left(frequency));

if grave=0 then  color='white';

else if grave=1 then do; color='black' ; XC=nat; Y=frequency+1; end;

run;

GraphGuy
Meteorite | Level 14

So, all the other subgroups will be in the bar segments, but the last one will be on top of the bar?  I think that could confuse users - they might assume the value on top of the bar is the total for the whole bar.

kmel56
Calcite | Level 5

I totally agree with you but I am working in a company that uses this chart for graphics, and i am automating their programs.

The other problem that i have is that sometimes there are some subgroups with small values 1 or 2 so It will be better that their text labels be on the right and not inside the subgroup bar, do you see the problem?

sfo
Quartz | Level 8 sfo
Quartz | Level 8

Hello,

 

I am applyong the below annotation to proc gplot (in which  want to change the color of the bar not the text) but I am not getting color that I have specified. Can you please help me.

 

Thanks.

 

data anno_text;

set data;
length function color $8;
xsys='2'; ysys='2'; when='a';
midpoint=dose;
group=dose;
subgroup=VAL;
position='e';
text=" ";
if VAL="A" then color='grey';
else if VAL="B" then color='blue';
run;

 

goptions reset=all;
axis1 label=(angle=90 f=arial h=2 "Yaxis") value=(f=arial h=2) ;
axis2 label=(f=arial h=2 justify=left "Dose (mg)") value=(f=arial h=2) ;
axis3 label=none value=none;

goptions display hby=2 fby=arial;


PROC GCHART DATA=data; 
VBAR DOSE/ DISCRETE GROUP=DOSE SUBGROUP=VAL annotate=anno_text G100 NOZERO FREQ=SUBJECT TYPE=PERCENT
maxis=axis2 gaxis=axis3 raxis=axis1 inside=percent width=10 space=10 gspace=5 ;
by DRUG;
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 12 replies
  • 10268 views
  • 0 likes
  • 3 in conversation