Data visualization with SAS programming

datalabel in hbar statement

Reply
Contributor
Posts: 40

datalabel in hbar statement

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 Smiley Happy

 

 

SAS Super FREQ
Posts: 1,148

Re: datalabel in hbar statement

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?

Contributor
Posts: 40

Re: datalabel in hbar statement

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;

 

 

SAS Super FREQ
Posts: 1,148

Re: datalabel in hbar statement

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

Contributor
Posts: 40

Re: datalabel in hbar statement

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

......

Ask a Question
Discussion stats
  • 4 replies
  • 382 views
  • 0 likes
  • 2 in conversation