BookmarkSubscribeRSS Feed
mft
Calcite | Level 5 mft
Calcite | Level 5

Hi there, 

 

I am trying to produce a graph like the one below. That is not my graph but just for reference.  In the graph below, the bar values are rotated vertically, I am trying to rotate my values at an angle. I read somewhere that the values will be automatically rotated to a vertical position when the values don't fit in the space, however I need to have my values rotated even though I only have 5 digits number ( for example 45,000).  

 

This is the code I am using and I am using SAS 9.4:

 

proc sgplot data=table1 noborder;
where label='Avg Size' and state=10;
format ld1 comma.;
vbar year/ response=ld1 datalabel datalabelattrs=(size=12)
barwidth =0.2
dataskin=gloss
baselineattrs=(thickness=0)
fillattrs=(color=green);
xaxis display=(nolabel noticks) ;
yaxis display=none ;
run;

 

Image result for sgplot tilt data value on top of  bar chart

8 REPLIES 8
PeterClemmensen
Tourmaline | Level 20

Hi and welcome to the SAS communities 🙂

 

You can use 

 

datalabelfitpolicy=rotate

in the VBAR Statement Options

DanH_sas
SAS Super FREQ

We currently do not have a ROTATEALWAYS option for DATALABELFITPOLICY; however, if the values are close to the edge of the bars, you can make the rotation kick in by shrinking the BARWIDTH a little more.

 

Hope this helps!

Dan

PeterClemmensen
Tourmaline | Level 20

I just learned something. I thought the DATALABELFITPOLICY=ROTATE would rotate the data label values no matter what.

 

@DanH_sas thank you for clarifying. Will we see a ROTATEALWAYS Option for DATALABELFITPOLICY in a future release?

DanH_sas
SAS Super FREQ

We'll see what we can do 🙂

 

Thanks!
Dan

mft
Calcite | Level 5 mft
Calcite | Level 5

Thank you for this information!

Ksharp
Super User

How about this one ?

 

proc summary data=sashelp.class nway;
class age sex;
var height;
output out=temp sum=;
run;
data temp;
 set temp;
 if sex='M' then h1=height;
  else h2=height;
run;

proc sgplot data=temp;
vbarparm category=age response=height  /group=sex groupdisplay=cluster ;
text x=age y=h1 text=h1/ discreteoffset=0.2 rotate=90 strip;
text x=age y=h2 text=h2/ discreteoffset=-0.2 rotate=90 strip;
run;
Jay54
Meteorite | Level 14

This should work.  I am thinking you can use TEXT statement with GROUP and GROUPDISPLAY=Cluster to match the VBARPARM.  This will make it more scale-able to different group levels.

Ksharp
Super User

Thanks. As you said.

 

proc summary data=sashelp.class nway;
class age sex;
var height;
output out=temp sum=;
run;


proc sgplot data=temp;
vbarparm category=age response=height  /group=sex groupdisplay=cluster ;
text x=age y=height text=height/group=sex groupdisplay=cluster rotate=90 strip;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 8 replies
  • 4150 views
  • 1 like
  • 5 in conversation