BookmarkSubscribeRSS Feed
Claus_Stenberg_DK
Calcite | Level 5

I have to plot some mean data by a group.

By default the names in the legend is then the names from the defined group.

Are the anyway you can refer to a another variable for to appear in the name in the legend.  

  

As an axample below: I want to plot the sashelp.cars  dataset and instead of having grouping variable MAKE

"Acura"  "Audi"

in the names legend I want to refer to the variable ORIGIN

"Asia" "Europe" 

Is that posible (sorry, not the most meanigfull example) ? 

 

proc summary data=sashelp.cars (obs=20)  nway;
class make;
var EngineSize Length;
id origin;
output out=plotds mean=avg_eng avg_len ;
run;


proc sgplot data=plotds;
 scatter x=avg_eng  y=avg_len / group=make   ;
run; 
3 REPLIES 3
Reeza
Super User

That doesn't make a heck of a lot of sense, but you can use a format to control the display of the variables. 

 

You create the format outside of the SGPLOT and apply it to the data with a format statement. 

 

 

ballardw
Super User

If you want the origin in the legend then use origin in the group statement.

Or is there something else you are attempting that does not work for?

Jay54
Meteorite | Level 14

Do you mean something like this?

Make and Origin may not have similar number of levels.  

May be better to just label the Origin on each marker.

 

proc summary data=sashelp.cars (obs=20) nway;
class make;
var EngineSize Length;
id origin;
output out=plotds mean=avg_eng avg_len ;
run;

ods graphics / reset attrpriority=none;
proc sgplot data=plotds nocycleattrs;
scatter x=avg_eng y=avg_len / group=origin name='a' markerattrs=(size=10) ;
scatter x=avg_eng y=avg_len / group=make datalabel=make markerattrs=(size=10) ;
keylegend 'a';
run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 3 replies
  • 2723 views
  • 0 likes
  • 4 in conversation