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


Hi All,

I have sas 9.3. I am using SGPLOT and I have set of series plot and the legend for the lines and it works fine.

However I also need to add the label to each lines using curvelabel option so that the eye movement is reduced.

The problem is when I use curvelabel option the legend disappears.

Is there a way that I could have both in my plot?

Thank you for your help.

P.S.

Here is the code and the output as an example.

/*THIS GIVES ME THE LEGEND*/

proc sgplot data=sashelp.stocks(where=(date >= "01jan2000"d and stock = "IBM")) ;;

title "Stock Trend : IBM";

series x=date y=close /legendlabel="CCCC";

series x=date y=low   /legendlabel="LLLL";

series x=date y=high  /legendlabel="HHHH";

run;

legend.png

Now I add the curvelabel option. It works but the LEGEND DISAPPEARS

proc sgplot data=sashelp.stocks(where=(date >= "01jan2000"d and stock = "IBM")) ;;

title "Stock Trend : IBM";

series x=date y=close /curvelabel='Close' curvelabelloc=inside curvelabelpos=max  legendlabel="CCCC";

series x=date y=low   /curvelabel='Low'   curvelabelloc=inside  curvelabelpos=max legendlabel="LLLL";

series x=date y=high  /curvelabel='High'  curvelabelloc=inside  curvelabelpos=max legendlabel="HHHH";

legend ;

run;

curvelabel.png

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Does this do what you need:

proc sgplot data=sashelp.stocks(where=(date >= "01jan2000"d and stock = "IBM")) ;;

title "Stock Trend : IBM";

series x=date y=close /curvelabel='Close' curvelabelloc=inside curvelabelpos=max  legendlabel="CCCC" name='a';

series x=date y=low   /curvelabel='Low'   curvelabelloc=inside  curvelabelpos=max legendlabel="LLLL" name='b';

series x=date y=high  /curvelabel='High'  curvelabelloc=inside  curvelabelpos=max legendlabel="HHHH" name='c';

keylegend 'a' 'b' 'c';

run;

View solution in original post

3 REPLIES 3
ballardw
Super User

Does this do what you need:

proc sgplot data=sashelp.stocks(where=(date >= "01jan2000"d and stock = "IBM")) ;;

title "Stock Trend : IBM";

series x=date y=close /curvelabel='Close' curvelabelloc=inside curvelabelpos=max  legendlabel="CCCC" name='a';

series x=date y=low   /curvelabel='Low'   curvelabelloc=inside  curvelabelpos=max legendlabel="LLLL" name='b';

series x=date y=high  /curvelabel='High'  curvelabelloc=inside  curvelabelpos=max legendlabel="HHHH" name='c';

keylegend 'a' 'b' 'c';

run;

DanH_sas
SAS Super FREQ

Ballardw is correct. By default, a curvelabel removes a plot from the auto legend because it is considered redundant information. Since the curve label was turned on for all three plot, the auto legend disappeared. However, you can override that behavior by creating your own legend, as in Ballardw's example.

P_S_
Obsidian | Level 7

Thanks Ballardw. It solves my problem.

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