10-25-2017 06:43 AM
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
10-25-2017 09:21 AM
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;
10-25-2017 04:10 PM - edited 10-25-2017 04:19 PM
Okay, thanks a lot. I will try that and let you know the outcome
I have the offsetmin and offsetmax set to 0.05 does that have any influence on the width of the bars?
yaxis display=(nolabel) offsetmin=0.05 offsetmax=0.05;
11-07-2017 02:51 AM
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.
a month ago - last edited a month ago
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 month ago
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".
a month ago
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.