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 " ";
Rick is likely suggesting a better visual. However, for vertical labels on x-axis, use FITPOLICY=ROTATEALWAYS and VALUESROTATE=VERTICAL
See:
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.
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.
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;
@Rick_SAS thanks, but I want the bars to be displayed vertically
Rick is likely suggesting a better visual. However, for vertical labels on x-axis, use FITPOLICY=ROTATEALWAYS and VALUESROTATE=VERTICAL
See:
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.
@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.
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.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.