BookmarkSubscribeRSS Feed
Mehdi_R
Fluorite | Level 6

Hello,

 

I'm using sgplot to plots bar graphs. I would like to add the number associated with each bar to be printed on each bar. When I use vbar statement, by the following options I can do so:

datalabel datalabelfitpolicy=rotate/none

 

But when I use hbar statement the datalabel option doesn't work with either of datalabelfitpolicy=none or datalabelfitpolicy=rotate or without datalabelfitpolicy. 

I will be thankful if anyone knows how I can activate datalabel option when using hbar.

Thanks 🙂

 

 

4 REPLIES 4
Jay54
Meteorite | Level 14

It should work the way you are describing it.  Label rotation is not helpful for HBAR.  Please include full code and data to debug.

What release of SAS are you using?

Mehdi_R
Fluorite | Level 6

I just realixed that when I have only two bars, it works, but in my actual example, I have about 100 bars (that's why I want to use hbar instead of vbar) and it doesn't show the labels.

 

I don't think the code is useful, but here you are:

 

The chapter variable has about 50 categories, and case variable has two categories. So when I run the code, I get about 100 bars:

 

 

options nodate nonumber;

ods pdf style=barcolors file = "R:\working\finished datasets\Chapters\admin\Specialty.pdf";

goptions device = pdf colors=(black) rotate=landscape;

 

ods graphics / height = 800 width = 700;

title font="helvetica/bold" height=10pt "Overall weighted Frequency of Physician Specialty";

title2 font="helvetica/italic" height=8pt "Stratified by Cases & Controls";

 

proc sgplot data = Overall_Freq2_Specialty;

vbar Chapter/group = case response = WgtFreq groupdisplay=cluster  datalabel;

xaxis  label =  "Physician Specialty" ;

yaxis label = "Frequency"  grid;

keylegend / position=right location=outside;

where chapter ~= "General Practice";

run;title;title2;

ods pdf close;

 

 

Jay54
Meteorite | Level 14

Helps to have the code that is NOT working (HBAR), WITH THE DATA.  Also SAS version.

Mehdi_R
Fluorite | Level 6

Sorry, I copied the other one. Just change "vbar" to "hbar". It doesn't work. Also, data is stored in a secure environment and I can't take it out. But the data layput is similar to this, but 50 chapters not 5:

chapter  case WgtFreq

1 1 5

1 0  10

2 1 2

2 0 6

3 1 5

3 0 9

4 1 10

4 0 15

5 1 20

5 0 15

......

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1699 views
  • 0 likes
  • 2 in conversation