Hi,
datalabel=... can be used to specified a variable which will use to display the information.
But there is nothing similar with seglabel. We can not specifiy seglabel=ageb.
Is there a workaround to display other values that the statistics associated with the group in a bar?
proc format;
value yr 12='12 Years Old'
13='13 Years Old'
14='14 Years Old'
15='15 Years Old'
16='16 Years Old';
run;
data class;
set sashelp.class;
ageb=put(age,yr.);
run;
ods graphics / width=15cm height=10cm noborder;
proc sgplot data=class noborder noautolegend;
vbar sex / group=age
seglabel;
run;
/*
*this will not work as seglabel cannot be followed by an equal sign;
proc sgplot data=class noborder noautolegend;
vbar sex / group=age
seglabel=ageb;
run;
proc sgplot data=class noborder noautolegend;
vbar sex / group=age
seglabel=age
seglabelformat=yr.;
run;
*/
ods graphics off;
Hi,
Here is the solution I finally got with sganno=:
data anno;
function = 'text';
textcolor= 'white';
x1space = 'datavalue';
y1space = 'datavalue';
justify = 'center';
width = 30;
xc1='F';
label='11 years old'; y1=.5; output;
label='12 years old'; y1=2; output;
label='13 years old'; y1=4; output;
label='14 years old'; y1=6; output;
label='15 years old'; y1=8; output;
xc1='M';
label='11 years old'; y1=.5; output;
label='12 years old'; y1=2.5; output;
label='13 years old'; y1=4.5; output;
label='14 years old'; y1=6; output;
label='15 years old'; y1=8; output;
label='16 years old'; y1=9.5; output;
run;
ods graphics / width=15cm height=10cm noborder;
proc sgplot data=sashelp.class noborder noautolegend sganno=anno;
vbar sex / group=age;
run;
ods graphics;
You can use a TEXT statement to overlay the values. You may want to add some offset or adjustment to have them positioned exactly where you want.
@xxformat_com wrote:
Hi,
datalabel=... can be used to specified a variable which will use to display the information.
But there is nothing similar with seglabel. We can not specifiy seglabel=ageb.
Is there a workaround to display other values that the statistics associated with the group in a bar?
proc format; value yr 12='12 Years Old' 13='13 Years Old' 14='14 Years Old' 15='15 Years Old' 16='16 Years Old'; run; data class; set sashelp.class; ageb=put(age,yr.); run; ods graphics / width=15cm height=10cm noborder; proc sgplot data=class noborder noautolegend; vbar sex / group=age seglabel; run; /* *this will not work as seglabel cannot be followed by an equal sign; proc sgplot data=class noborder noautolegend; vbar sex / group=age seglabel=ageb; run; proc sgplot data=class noborder noautolegend; vbar sex / group=age seglabel=age seglabelformat=yr.; run; */ ods graphics off;
Hi,
Here is the solution I finally got with sganno=:
data anno;
function = 'text';
textcolor= 'white';
x1space = 'datavalue';
y1space = 'datavalue';
justify = 'center';
width = 30;
xc1='F';
label='11 years old'; y1=.5; output;
label='12 years old'; y1=2; output;
label='13 years old'; y1=4; output;
label='14 years old'; y1=6; output;
label='15 years old'; y1=8; output;
xc1='M';
label='11 years old'; y1=.5; output;
label='12 years old'; y1=2.5; output;
label='13 years old'; y1=4.5; output;
label='14 years old'; y1=6; output;
label='15 years old'; y1=8; output;
label='16 years old'; y1=9.5; output;
run;
ods graphics / width=15cm height=10cm noborder;
proc sgplot data=sashelp.class noborder noautolegend sganno=anno;
vbar sex / group=age;
run;
ods graphics;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.