@ballardw wrote: From the SGPLOT documentation for HBAR: Interactions When a group variable is used with the CATEGORYORDER= option, the response values for each group segment become the sorting key. CATEGORYORDER sorts first by the response statistic and then displays the GROUP values sorted within each category. Thank you for a fast and good solution/workaround! I guess my problem is expected behaviour then. But I don't really understand why category order has to interfere with grouporder. If I wanted categoroes and groups orderede by size I would expect to use something like categoryorder=respdesc grouporder=respdesc Do you think I can talk SAS support into filing it as a bug or change request? Your solution works like a charm, but I'm going to make around 20 graphs like that one in a single report. The code will not be easy to maintain. I have to choose between writing a lot of code or writing a semi complicated macro. Performance will probably be an issue to. Subsetting of data will be parameterized, so summarization must be done during report execution. p.s. I changed your solution a little to minimize reading/writing datasets (your code was more explanatory): proc summary data=sashelp.heart missing completetypes;
class smoking_status sex;
types smoking_status smoking_status*sex;
output out=work.summary ;
run;
proc sql;
create table work.plot as
select order_data.category_total_freq, plot_data.*
from work.summary(where=(_type_=3)) as plot_data
left join
work.summary(where=(_type_=2) rename=(_FREQ_=category_total_freq)) as order_data
on plot_data.smoking_status=order_data.smoking_status
order by order_data.category_total_freq desc, plot_data.sex
;
quit;
proc sgplot data=work.plot;
hbarparm category=Smoking_Status response=_FREQ_ / group=sex;
yaxistable _FREQ_ / class=sex position=left location=inside ;
run;
... View more