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 2024

Innovate_SAS_Blue.png

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. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

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