BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
USchu
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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.

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

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.

USchu
Calcite | Level 5

Thanks, thats it. Sorry for re-mention this topic, I obviously did not use the best keys for my search

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1076 views
  • 1 like
  • 2 in conversation