Graphics Programming

Data visualization using SAS programming, including ODS Graphics and SAS/GRAPH. Charts, plots, maps, and more!
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
xxformat_com
Barite | Level 11

Hi,

I'm wondering when the name= option of the xaxistable/yaxistable could be used.

 

I've created an example where name='test' is not referenced anywhere.

 

proc sql;
    create table class as
    select sex, mean(height) as mean_height
    from sashelp.class
    group by sex;
run;

proc sgplot data=class ;
    vbarbasic sex / response=mean_height;
    xaxistable mean_height / name='test';
    legenditem type=text name='A' / text='xx'
                                    label='Demo';
    keylegend 'A' / position=right;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@xxformat_com wrote:
When I added 'text' in keylegend nothing was displayed. Therefore I was wondering if it was recognized and what text would then be displayed in the legend.

Legends would not be created in a graph with with a single Plot statement (i.e. Vbarbasic) with no overlay or group variable. XAXISTABLE by itself doesn't create a legend as it is not a plot statement.

 

Contrived and not a suggested graph but demonstrates name= with multiple XAXISTABLE statements:

proc sgplot data=sashelp.class ;
    vbar sex / response=height stat=mean group=age name='bar';
    xaxistable height / colorgroup=age  name='test';
    xaxistable weight / colorgroup=sex  name='test2';
    keylegend  'test' / position=bottom title='Mean Height';
    keylegend  'test2'/ position=right title='Weights';
run;

Note the different colorgroup variable, what that does to the row variables.

Default behavior is going to reuse colors which is why this isn't a very good graph but you were asking about Name= and shows that you can get different somewhat different legends for different XAXISTABLEs.

 

View solution in original post

3 REPLIES 3
ballardw
Super User

Pretty much the same reasons as having the Name= option for any of the plots: control of keylegend output.

Remember that you can have multiple XAXISTABLE statements in a single plot. If you want to create a Keylegend output you have to be able to tell keylegend which one to use.

Also, you may want to use multiple Keylegend statements to create multiple legends and again need names to control which legend options go with which item.

xxformat_com
Barite | Level 11
When I added 'text' in keylegend nothing was displayed. Therefore I was wondering if it was recognized and what text would then be displayed in the legend.
ballardw
Super User

@xxformat_com wrote:
When I added 'text' in keylegend nothing was displayed. Therefore I was wondering if it was recognized and what text would then be displayed in the legend.

Legends would not be created in a graph with with a single Plot statement (i.e. Vbarbasic) with no overlay or group variable. XAXISTABLE by itself doesn't create a legend as it is not a plot statement.

 

Contrived and not a suggested graph but demonstrates name= with multiple XAXISTABLE statements:

proc sgplot data=sashelp.class ;
    vbar sex / response=height stat=mean group=age name='bar';
    xaxistable height / colorgroup=age  name='test';
    xaxistable weight / colorgroup=sex  name='test2';
    keylegend  'test' / position=bottom title='Mean Height';
    keylegend  'test2'/ position=right title='Weights';
run;

Note the different colorgroup variable, what that does to the row variables.

Default behavior is going to reuse colors which is why this isn't a very good graph but you were asking about Name= and shows that you can get different somewhat different legends for different XAXISTABLEs.

 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 635 views
  • 1 like
  • 2 in conversation