Hello everybody,
I have a problem with the axistable for a vbar statement in sgplot.
Please try the following example:
DATA test;
INPUT time $ result $ no @@;
CARDS;
Begin a 1 Begin a 1 Begin a 1 Begin b 1 Begin b 1
End a 1 End b 1 End b 1 End b 1 End b 1
;
RUN;
PROC SGPLOT DATA=test;
VBAR time / GROUP=result GROUPDISPLAY=STACK GROUPORDER= DESCENDING STAT=SUM NOSTATLABEL;
XAXISTABLE no / STAT=SUM CLASSDISPLAY=STACK CLASSORDER= DESCENDING LOCATION=inside POSITION=BOTTOM;
RUN;
You will see, that the order in the XAXISTABLE stacks is reverse to the order in the graphic-stack itself.
Changing the CLASSORDER-statement does nothing, it is redundant. Changing the GROUPORDER-statement turns both, grafic stack and table stack. So again the order is reverse to each other.
Does anyone have a solution how to bring both in the same order?
(SAS version 9.4 TS Level 1M4 on windows)
Thanks
Uli
Hallo @USchu and welcome to the SAS Support Communities!
Looking at the last post of the 2020 thread stacked barchart - how to order the legend and the xaxis table? (which was probably the solution, although the original poster didn't mark it as such) it appears that the VBARPARM statement is the key to the solution.
So you would need to presummarize the data
proc summary data=test nway;
class time result;
var no;
output out=want sum=;
run;
and then use something like
proc sgplot data=want;
vbarparm category=time response=no / group=result grouporder=descending;
xaxistable no / class=result location=inside;
run;
Here I use the default of the CLASSORDER= option, which is DATA, but you could explicitly specify classorder=ascending to obtain the same result with input dataset WANT. The important point is that now CLASSORDER= (in the XAXISTABLE statement) and GROUPORDER= (in the VBARPARM statement) can be specified independently of each other, whereas with the VBAR statement the CLASSORDER= option is ignored (see documentation linked above). So the combination of grouporder=ascending and classorder=descending reverses both orders, maintaining the consistency that you want.
Hallo @USchu and welcome to the SAS Support Communities!
Looking at the last post of the 2020 thread stacked barchart - how to order the legend and the xaxis table? (which was probably the solution, although the original poster didn't mark it as such) it appears that the VBARPARM statement is the key to the solution.
So you would need to presummarize the data
proc summary data=test nway;
class time result;
var no;
output out=want sum=;
run;
and then use something like
proc sgplot data=want;
vbarparm category=time response=no / group=result grouporder=descending;
xaxistable no / class=result location=inside;
run;
Here I use the default of the CLASSORDER= option, which is DATA, but you could explicitly specify classorder=ascending to obtain the same result with input dataset WANT. The important point is that now CLASSORDER= (in the XAXISTABLE statement) and GROUPORDER= (in the VBARPARM statement) can be specified independently of each other, whereas with the VBAR statement the CLASSORDER= option is ignored (see documentation linked above). So the combination of grouporder=ascending and classorder=descending reverses both orders, maintaining the consistency that you want.
Thanks, thats it. Sorry for re-mention this topic, I obviously did not use the best keys for my search
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.