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)))
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.