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

 

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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