BookmarkSubscribeRSS Feed
pmksasbi
Fluorite | Level 6

Hi All, I am generating horizontal bar charts using proc gchart. but the values inside horizontal bars are not in any proper order . i want the values inside horizontal bar to be in descending order . and also the first highest value should have a color of green ,the next highest shld be blue and least should be orange. how can i get this. I used proc gchart code and i cannot atatch any images from my desktop. below is a sample, i want 75 to be first and with green ,next 45 blue and last 25 orange. please take this graph as my output.

 

-------------|-----------|------------------|

    25        |     75     |    45              |

-------------|-----------|------------------|

 

-------------|-----------|------------------|

    25        |     75     |    45              |

-------------|-----------|------------------|

---------------------------------------------------------------------

0                 20                40              60       80           100  

Thanks,

Mahesh

7 REPLIES 7
Reeza
Super User

Include your current code - ideally you can use a SASHELP dataset so we can replicate the example. 

Are you set on using GCHART or do you have the option to use SGPLOT?

pmksasbi
Fluorite | Level 6

I am limited to gchart, SGPLOT i have some issues related to java .

 

axis1 label=(angle=90)
value=(justify=right) label=none value=none ;
axis2 label=(" ")
order=(0 to 100 by 20)
minor=none label=none noplane;
axis3 label=none;

/* Define legend options */
legend1 frame;
pattern4 v=s c='#0080FF';
pattern3 v=s c='#7E7E7E';
pattern2 v=s c='#FF8000';
pattern6 v=s c='#00003C';
pattern1 v=s c='#54B948';
pattern5 v=s c='#00FFFF';


/* Generate the graph */
proc gchart data=work.sample_data;
hbar desc / subgroup=type2
sumvar=values
legend=legend1
nostats
maxis=axis1
raxis=axis2
annotate=barlabel noframe nolegend descending;
format values pct0dec.;
run;
quit;

ballardw
Super User

If your sample_data set is summarized data an you are only displaying the existing values I would try:

proc sort data=work.sample_data;
  by values;
run;

proc gchart data=work.sample_data;
   hbar desc / subgroup=type2
   sumvar=values
   legend=legend1
   nostats
   maxis=axis1
   raxis=axis2
   annotate=barlabel noframe nolegend descending;
   format values pct0dec.;
run;
quit; 

The first value seen by the proc is usually grabbed to be the bottom and the associated type2 should appear in the same place.

 

If your data is not summarized it may help to summarize it first with proc means or summary, then sort.

The Type2 order needs to change from bar to bar you need a completely different procedure and approach.

 

Without data and the annotate dataset data it's a bit hard to make more concrete suggestions.

pmksasbi
Fluorite | Level 6

I was able to achieve , what i was looking for , but my colors are being jumbled for some scenarios. i used legend and defined colors from pattern1 to pattern6 .but colors from bar1 are moving to bar2. any help .

 

 

goptions reset=all border cback=white htitle=5.0 htext=4.0 imagestyle= vsize=5.17in hsize=7.10in;
goptions device=jpeg gsfname=out;
goptions xpixels=500 ypixels=500;
goptions cback=white;
goptions border
gunit=pct htitle=5.0 htext=4.0 ctext=gray33;

ODS GRAPHICS ON / width=15in;
ODS GRAPHICS ON / height=20in;

ODS LISTING CLOSE;
ODS HTML path="&rptoutpth." body="&name..htm" style=htmlblue
gpath="&rptoutpth./&img_name..jpg";

/* Define the axis characteristics */
axis1 label=(angle=90) value=(justify=right) label=none value=none;
axis2 label=(" ") order=(0 to 100 by 20) minor=none label=none noplane;
axis3 label=none;

/* Define legend options */
legend1 frame;
pattern1 v=s c='#0080FF';
pattern2 v=s c='#7E7E7E';
pattern3 v=s c='#FF8000';
pattern4 v=s c='#00003C';
pattern5 v=s c='#54B948';
pattern6 v=s c='#00B0F0';

/* Generate the graph */
PROC GCHART data=work.test;
hbar desc / subgroup=type2 discrete ascending
sumvar=values
legend=legend1
nostats
maxis=axis1
raxis=axis2
annotate=barlabel noframe nolegend;
format values pct0dec.;
RUN;
QUIT;

ODS HTML CLOSE;
ODS LISTING;

ballardw
Super User

@pmksasbi wrote:

I was able to achieve , what i was looking for , but my colors are being jumbled for some scenarios. i used legend and defined colors from pattern1 to pattern6 .but colors from bar1 are moving to bar2. any help .

 


One of the addtions in the SG graphics procedures is the ability to define an attribute map data set (ATTRMAP option) do define characteristics for values of categorical variables so bars, markers and lines don't change from graph to graph dependent on order or even appearance with a specific graph.

 

So you may need to decide which is more important: have the "largest" value to the left of the bar, or the same value across different displays or to investigate proc sgplot.

pmksasbi
Fluorite | Level 6

For now, i am not intrested in order inside graph . The horizontal bars should always follow specific colors every time they execute. The colors inside the bar should be standard and should not change.

 

Horizontal bar1: Grey,Light Blue, Dark blue

Horizontal bar2: Yellow,orange,green.

 

is there a way where i can keep this fixed. in one of the test cases the colors got jumbled. 

GraphGuy
Meteorite | Level 14
I think to do what you want to do with gchart, you're going to have to assign numeric values to use as your subgroup= (and have them in the order you want), and then use a user-defined-format so that the numeric values show up as the text that you want in the legend.

And for the labels on the bar segments to show up in different colors, you'll need to annotate them.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 1669 views
  • 0 likes
  • 4 in conversation