BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Anita_n
Pyrite | Level 9

Dear all,

I have a problem using sgplot fitpolicy. Nothing  seems to work.

I used datalabel and want the values to rotate so that they are horizontally displayed but it's not working (see myfilename1.pdf). Please not that this only seen when the results is outputted as pdf.

 

Is there any way to suppress 0 values?

 

My second problem is the xaxis fitpolicy =rotate which also doesn't work. Attached are all my test data.

I will appreciate any help.

 

Here is my code

ods graphics/ imagefmt = pdf width= 3in height= 2in noborder push;
goptions device=pdfc gunit=pct rotate=landscape ftext= "verdana" ;
ods listing gpath="mypath/myfolder" ;
ods graphics on / reset=index imagename="myfilename";

footnote justify=center "Cases per Agegroup per year" ;
proc sgplot data=test dattrmap=myattrmap pad=(bottom=5%) noautolegend noborder; 
format sex $sex.;
xaxis grid type=discrete discreteorder=data;
vbar AGEGROUP /response=CASES_PER_AGEGROUP group=sex datalabel datalabelfitpolicy= rotate
datalabelattrs=(size=0.25 color=black family= "verdana") groupdisplay=cluster attrid=sex
barwidth=0.9 missing ; 
xaxis  display= (nolabel) valueattrs=(family="verdana" size=8pt) fitpolicy=rotate ValuesRotate=Vertical;
yaxis values=(0 to 250 by 5) display=(nolabel) valueattrs=(family="verdana" size=8pt) grid offsetmin=0.0 offsetmax=0.0;
keylegend / location=inside position=topleft across=0 title="" valueattrs=(size=10 family="verdana") outerpad=(top=0.2cm) noborder;
run;
footnote " ";
1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

Rick is likely suggesting a better visual.  However, for vertical labels on x-axis, use FITPOLICY=ROTATEALWAYS and VALUESROTATE=VERTICAL

 

See:

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=grstatproc&docsetTarget=p...

 

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=grstatproc&docsetTarget=p...

 

If you don't have the latest version of SAS, you can save out the GTL by using TMPLOUT option, then add the appropriate options to the XAXISOPTS->DISCRETEOPTS bundle for TICKVALUEFITPOLICY and TICKVALUEROTATION.

 

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=grstatgraph&docsetTarget=...

 

View solution in original post

8 REPLIES 8
GraphGuy
Meteorite | Level 14

I think the xaxis fitpolicy=rotate will only be used if the graph can't fit the text in its default way. As a test, you could try making the graph much more narrow (where the text along the xaxis wouldn't fit), and see if the fitpolicy=rotate is then honored.

 

 

Rick_SAS
SAS Super FREQ

If your goal is to clearly label the categories, you might consider exchanging the X and Y axes and using HBAR to draw the graph. For example:

proc sgplot data=sashelp.cars(where=(Origin^='Europe'));
   hbar Type / group=origin groupdisplay=cluster;
run;
Anita_n
Pyrite | Level 9

@Rick_SAS  thanks, but I want the bars to be displayed vertically 

Jay54
Meteorite | Level 14

Rick is likely suggesting a better visual.  However, for vertical labels on x-axis, use FITPOLICY=ROTATEALWAYS and VALUESROTATE=VERTICAL

 

See:

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=grstatproc&docsetTarget=p...

 

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=grstatproc&docsetTarget=p...

 

If you don't have the latest version of SAS, you can save out the GTL by using TMPLOUT option, then add the appropriate options to the XAXISOPTS->DISCRETEOPTS bundle for TICKVALUEFITPOLICY and TICKVALUEROTATION.

 

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=grstatgraph&docsetTarget=...

 

Anita_n
Pyrite | Level 9

@Jay54 Thanks, that worked fine. Any idea how I can rotate the datalabelfitpolicy?

It's just that my client wants the data to be displayed vertically.

 

Jay54
Meteorite | Level 14

My guess would be DATALABELFITPOLICY=NONE. To remove the zero values, I suggest you can create a new character variable in your data (say 'label') which has the formatted summarized bar value by group and blank if zero. Then use DATALABEL=label.

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=grstatproc&docsetTarget=n...

 

BTW, these are also some benefits of HBAR which has a better arrangement of long tick values for many categories and better (horizontal) display of the bar label.

Anita_n
Pyrite | Level 9

@Jay54 @Rick_SAS : Thank you very much

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 8 replies
  • 2671 views
  • 2 likes
  • 4 in conversation