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

Hi,

I use grouped&stacked bar chart for my data set. And I need groups in that bar chart to have certain order. When using the simplest bar chart you can do it with midpoints option. But I can't find the way to use it correct for grouped&stacked bar chart.

For example:

/*data*/

data sample;
length week agent type $12.;
do week='week1','week2','week3';
do agent='agent1','agent2','agent3','agent4';
do type='type1','type2';

num=ceil(ranuni(0)*10);
output;

end;
end;
end;
run;

/*gchart*/

%_eg_conditional_dropds(WORK.SORTTempTableSorted);
PROC SQL;
CREATE VIEW WORK.SORTTempTableSorted AS
  SELECT T.type, T.week, T.agent, T.num
FROM WORK.SAMPLE as T
;
QUIT;
Legend1
FRAME
;
Axis1
STYLE=1
WIDTH=1
MINOR=NONE


;
Axis2
STYLE=1
WIDTH=1


;


;
TITLE;
TITLE1 "title";
FOOTNOTE;
FOOTNOTE1 "footnote";
PROC GCHART DATA=WORK.SORTTempTableSorted
;
VBAR
  type
/
SUMVAR=num
SUBGROUP=agent
GROUP=week
CLIPREF
FRAME TYPE=SUM
LEGEND=LEGEND1
COUTLINE=BLACK
RAXIS=AXIS1
MAXIS=AXIS2
;

RUN; QUIT;
%_eg_conditional_dropds(WORK.SORTTempTableSorted);
TITLE; FOOTNOTE;

Is there any way to have groups in a special order: e.g. 'week2' 'week1' 'week3'?     (using      midpoints='week2' 'week1' 'week3'      gives incorrect result...)

Thank's in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
need_some_help
Calcite | Level 5

It's funny vut only after posting this message I found somethinf useful in documentation I've already read)):

there is rather simple way:

%_eg_conditional_dropds(WORK.SORTTempTableSorted);


PROC SQL;
CREATE VIEW WORK.SORTTempTableSorted AS
  SELECT T.type, T.week, T.agent, T.num
FROM WORK.SAMPLE as T
;
QUIT;
Legend1
FRAME
;
Axis1
STYLE=1
WIDTH=1
MINOR=NONE


;
Axis2
STYLE=1
WIDTH=1

;

/*!!!!!!!!!*/
Axis3
order=('week2' 'week1' 'week3') ;
/*!!!!!!!!!*/

;
TITLE;
TITLE1 "title";
FOOTNOTE;
FOOTNOTE1 "footnote";
PROC GCHART DATA=WORK.SORTTempTableSorted
;
VBAR
  type
/
SUMVAR=num
SUBGROUP=agent
GROUP=week
CLIPREF
FRAME TYPE=SUM
LEGEND=LEGEND1
COUTLINE=BLACK
RAXIS=AXIS1
MAXIS=AXIS2
/*!!!!!!!!!*/
GAXIS=AXIS3;
/*!!!!!!!!!*/
;

RUN; QUIT;
%_eg_conditional_dropds(WORK.SORTTempTableSorted);
TITLE; FOOTNOTE;

Merphy's law)))

View solution in original post

1 REPLY 1
need_some_help
Calcite | Level 5

It's funny vut only after posting this message I found somethinf useful in documentation I've already read)):

there is rather simple way:

%_eg_conditional_dropds(WORK.SORTTempTableSorted);


PROC SQL;
CREATE VIEW WORK.SORTTempTableSorted AS
  SELECT T.type, T.week, T.agent, T.num
FROM WORK.SAMPLE as T
;
QUIT;
Legend1
FRAME
;
Axis1
STYLE=1
WIDTH=1
MINOR=NONE


;
Axis2
STYLE=1
WIDTH=1

;

/*!!!!!!!!!*/
Axis3
order=('week2' 'week1' 'week3') ;
/*!!!!!!!!!*/

;
TITLE;
TITLE1 "title";
FOOTNOTE;
FOOTNOTE1 "footnote";
PROC GCHART DATA=WORK.SORTTempTableSorted
;
VBAR
  type
/
SUMVAR=num
SUBGROUP=agent
GROUP=week
CLIPREF
FRAME TYPE=SUM
LEGEND=LEGEND1
COUTLINE=BLACK
RAXIS=AXIS1
MAXIS=AXIS2
/*!!!!!!!!!*/
GAXIS=AXIS3;
/*!!!!!!!!!*/
;

RUN; QUIT;
%_eg_conditional_dropds(WORK.SORTTempTableSorted);
TITLE; FOOTNOTE;

Merphy's law)))

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

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
  • 1 reply
  • 1325 views
  • 0 likes
  • 1 in conversation