BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Anita_n
Pyrite | Level 9

Hi all,

I used sgplot to create a scatter and series plot. I get two legends as result. How can are supress one since they are both the same. 

1 ACCEPTED SOLUTION

Accepted Solutions
djrisks
Barite | Level 11

Hello,

 

As @Reeza and @DanH_sas said, you can use the KEYLEGEND statement, with the NAME option. Here is an example, that you can use below to understand things better. Also there may not be any use for you to use the SCATTER statement, because you can also use the MARKERS option in the SERIES statement to produce the markers.

 

data stocks;
  set sashelp.stocks;
  emphasis = 2;
  if stock eq 'Microsoft' then emphasis=1;
run;

 

title 'Microsoft Compared to IBM and Intel';
proc sgplot data=stocks (where=(date >= "01jan2003"d));
  series x=date y=close / group=stock grouplc=emphasis name="leg"; 
  scatter x=date y=close / group=stock;
  keylegend "leg";
run;

View solution in original post

3 REPLIES 3
Reeza
Super User
Look into KEYLEGEND statement.
DanH_sas
SAS Super FREQ

Use the NAME option on one of the plots, and reference that name from the KEYLEGEND statement (as @Reeza mentioned). That will give you the one legend you want.

djrisks
Barite | Level 11

Hello,

 

As @Reeza and @DanH_sas said, you can use the KEYLEGEND statement, with the NAME option. Here is an example, that you can use below to understand things better. Also there may not be any use for you to use the SCATTER statement, because you can also use the MARKERS option in the SERIES statement to produce the markers.

 

data stocks;
  set sashelp.stocks;
  emphasis = 2;
  if stock eq 'Microsoft' then emphasis=1;
run;

 

title 'Microsoft Compared to IBM and Intel';
proc sgplot data=stocks (where=(date >= "01jan2003"d));
  series x=date y=close / group=stock grouplc=emphasis name="leg"; 
  scatter x=date y=close / group=stock;
  keylegend "leg";
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1832 views
  • 3 likes
  • 4 in conversation