Data visualization with SAS programming

Creating Data Labels on Bar Chart

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 17
Accepted Solution

Creating Data Labels on Bar Chart

Hello,

 

I am trying to add data labels to my bar chart. Currently I am getting the variable instead of an actual value in percent.

 

Can you help?

 

Code:

title 'Game Attendance Percentages';
proc sgplot data=profoot.pro_football_segments;
	hbar game_attendance /datalabel=game_attendance stat=percent  fillattrs=(color=grey);
	xaxis label='Percentage of Game Attendance' labelattrs=(size=12);
	yaxis label='Game Attendance' labelattrs=(size=12);
run; 

Log:

 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 61         
 62         title 'Game Attendance Percentages';
 63         proc sgplot data=profoot.pro_football_segments;
 64         hbar game_attendance /datalabel=game_attendance stat=percent  fillattrs=(color=grey);
 65         xaxis label='Percentage of Game Attendance' labelattrs=(size=12);
 66         yaxis label='Game Attendance' labelattrs=(size=12);
 67         run;
 
 NOTE: PROCEDURE SGPLOT used (Total process time):
       real time           0.79 seconds
       cpu time            0.29 seconds
       
 NOTE: There were 473 observations read from the data set PROFOOT.PRO_FOOTBALL_SEGMENTS.
 
 68         
 69         OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 82         

Results:

Capture.JPG


Accepted Solutions
Solution
‎04-18-2017 03:04 PM
Super Contributor
Posts: 400

Re: Creating Data Labels on Bar Chart

Simply erase the 

 

=game_attendance

from your hbar options so that the code is

 

title 'Game Attendance Percentages';
proc sgplot data=profoot.pro_football_segments;
	hbar game_attendance / datalabel stat=percent  fillattrs=(color=grey);
	xaxis label='Percentage of Game Attendance' labelattrs=(size=12);
	yaxis label='Game Attendance' labelattrs=(size=12);
run; 

 

 

 

View solution in original post


All Replies
Solution
‎04-18-2017 03:04 PM
Super Contributor
Posts: 400

Re: Creating Data Labels on Bar Chart

Simply erase the 

 

=game_attendance

from your hbar options so that the code is

 

title 'Game Attendance Percentages';
proc sgplot data=profoot.pro_football_segments;
	hbar game_attendance / datalabel stat=percent  fillattrs=(color=grey);
	xaxis label='Percentage of Game Attendance' labelattrs=(size=12);
	yaxis label='Game Attendance' labelattrs=(size=12);
run; 

 

 

 

Occasional Contributor
Posts: 17

Re: Creating Data Labels on Bar Chart

Thank you! I had tried that previously but it wasn't working.

 

I appreciate your help!

Super Contributor
Posts: 400

Re: Creating Data Labels on Bar Chart

Anytime Smiley Happy

Post a Question
Discussion Stats
  • 3 replies
  • 79 views
  • 2 likes
  • 2 in conversation