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 now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.