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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
xxformat_com
Barite | Level 11

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;

sganno.JPG

 

 

View solution in original post

2 REPLIES 2
Reeza
Super User

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;



 

xxformat_com
Barite | Level 11

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;

sganno.JPG

 

 

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

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1429 views
  • 0 likes
  • 2 in conversation