I have plotted hbar chart with sgplot for different customers. The problem I have is if the plot has more than 1 bar the widths are okay but if the plot outputs only one bar the width becomes double. Is there any way I can make the width fixed no matter the number of bars created. I have already used the hbar statement barwidth=0.8 but this is not helping. I will appreciate any help. Thanks in advance
There is no way to set a fixed bar width that will apply to all cases. SG computes such things outside in, not inside out. When there is only one category, the computations are a bit different. We can look into it.
However, If you know you have a one category situation, you can try setting the offsetmin and offsetmax on the category axis to reduce the bar width. yaxis offsetmin=0.3 offsetmax=0.3;
sorry I was on holidays. I came back today and tried your suggestion but it didn't work. Is there any other way I can adjust the width?
I will be glad if any one can help.
Am just thinking of using if statement. To say if number of bars less than 4 then width=? else width =?
but I haven't tried that yet.
sorry for repling so late. I was a little bit busy with some other issues. Here is the code for Program. The problem is that the width decreases with the number of bars. I do not want that, I want the width to be fix no matter the number of bars. I hope you can help.
Thanks in advance
proc import datafile= "saslibrary\test1.xls" out=test dbms=xls replace; getnames=yes; run; %macro report (); %do i = 501 %to 505 ; proc sgplot data=test pad=(bottom=5%); styleattrs datacolors=(red); yaxis grid type=discrete discreteorder=data; hbar sport_typ /response=count barwidth=0.8 missing datalabel = count; yaxis display=(nolabel) offsetmin=0.05 offsetmax=0.05; xaxis label='Number of Athletes' grid offsetmin=0.0 offsetmax=0.05; where rep_id = &i; run; title " "; %end; %mend report; %report ();
A few things. Like in many other SAS programs, you do not need a macro. Sort your data by rep_id and use a BY statement in PROC SGPLOT instead as in this small example
proc sort data=sashelp.class; by sex; run; proc sgplot data=sashelp.class; by sex; scatter x=height y=weight; run;
I don't think it is possible to fix a bar width, so it does not change with the number of bars in your plot. As the documentation states, the BARWIDTH statement "specifies the width of the bars as a ratio of the maximum possible width".
Please see my previous answer to this question. "There is no way to set a fixed bar width that will apply to all cases. SG computes such things outside in, not inside out." For a set graph size, the bar width will depend on the number of bars in the graph. More bars -> less bar width.
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.
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.