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!
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)))
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)))
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.