BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
lichee
Quartz | Level 8

Hi all,

 

I wanted to display two series of data (yMean and zMean) with the same axis (month). The code is as below. Somehow there is overlapped legend labels ("Series 1"). Also I don't need "yMean" legend label to show. Can anyone guide to modify my code? Thank you! 

 

ods graphics on;
proc sgplot data=mydata noautolegend;
series x=Month y=yMean/lineattrs=(color=blue) legendlabel="Series 1";
keylegend /location=inside position=topleft;
scatter x=Month y=yMean/markerfillattrs=(color=blue) ;
series x=Month y=zMean/lineattrs=(color=red pattern=dash) legendlabel="Series 2";
keylegend /location=inside position=topleft;
scatter x=Monthy=zMean/markerfillattrs=(color=red);
yaxis values=(0 to 400 by 50) label="Avarage number of Participants";
xaxis values=(1 to 10 by 1) label="Month";
run;

lichee_1-1712287738545.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @lichee,

 

I think the simplest solution is to reorder the statements: first, the two SERIES statements, then the KEYLEGEND statement (delete the second KEYLEGEND statement -- this causes the overlapped labels) and only after that the SCATTER statements.

 

Alternatively, you can use the NAME= option in the SERIES statements and list the names of interest in the KEYLEGEND statement.

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

Hi @lichee,

 

I think the simplest solution is to reorder the statements: first, the two SERIES statements, then the KEYLEGEND statement (delete the second KEYLEGEND statement -- this causes the overlapped labels) and only after that the SCATTER statements.

 

Alternatively, you can use the NAME= option in the SERIES statements and list the names of interest in the KEYLEGEND statement.

DanH_sas
SAS Super FREQ

Th key here is having only one legend positioned at the top left. To include everything in the legend, remove the NOAUTOLEGEND option and just have one KEY:EGEND statement to telling it move to the top left. If you want only the SERIES plots in the legend, you should do as @FreelanceReinh mentioned and use the NAME option on the SERIES plots and list the names on the KEYLEGEND statement.

 

It's also important to note that a KEYLEGEND statement with no names listed is how you normally control the AUTOLEGEND, but that legend was disabled by the NOAUTOLEGEND option. Normally, the position of a KEYLEGEND statement does not matter, but I'm thinking that a "positional" AUTOLEGEND was created due to these mix of options. As a rule, use "no name" KEYLEGEND statements for only AUTOLEGENDS; otherwise, names should be specified. 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 262 views
  • 1 like
  • 3 in conversation