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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 1664 views
  • 0 likes
  • 2 in conversation