The group order sorting algorithm with the GROUPORDER= option set to ASCENDING or DESCENDING differs from the default sorting algorithm


When you create a grouped bar chart with the SGPLOT or SGPANEL procedure, the bars are sorted using an ASCII binary sort by default.

However, when you specify the GROUPORDER=ASCENDING or GROUPORDER=DESCENDING option in the HBAR or VBAR statement in PROC SGPLOT or PROC SGPANEL, the bars are sorted using a linguistic sorting algorithm.

To ensure that your bars are sorted using the desired algorithm, sort your data using PROC SORT with the SORTSEQ option to specify the sort sequence. Then include the GROUPORDER=DATA option in the HBAR or VBAR statement in PROC SGPANEL or PROC SGPLOT.

The following sample code creates a descending bar chart using a binary sort. 

title 'Descending bars with linguistic sort';
proc sgplot data=sashelp.cars;
   where type ne "Hybrid";
   vbar origin / response=mpg_city group=type
                 groupdisplay=cluster stat=mean
                 grouporder=descending;
run;

proc sort data=sashelp.cars out=cars sortseq=binary;
   where type ne "Hybrid";
   by descending type;
run;

title 'Descending bars with binary sort';
proc sgplot data=cars;
   vbar origin / response=mpg_city group=type
                 groupdisplay=cluster stat=mean
             grouporder=data;
run;