<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Multiple legends PROC SGPLOT in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760155#M21810</link>
    <description>&lt;P&gt;I just made a group variable with the text you wanted for the equation and then used that as the GROUP statement in the SERIES plot.&amp;nbsp; I can then add that to the legend to get it how you're showing.&amp;nbsp; By then also including that variable in the BY statement I can get one equation per page.&amp;nbsp; You can use the same technique to make one graph at a time as well if you use the WHERE statement I commented out to select one at a time and it'll look the same (but then you can customize individual axes/colors/etc.).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data test;
    length formula $100.;
    
    formula='Equation: x**2';
    do x=0 to 10;
        y=x**2;output;
    end;
    formula='Equation: 2x-5';
    do x=0 to 10;
        y=2*x-5;output;
    end;
    formula='Equation: log(x)';
    do x=0 to 10;
        if x=0 then y=log(0.0001);
        else y=log(x);
        output;
    end;
run;

options nobyline;
ods pdf file='~/ibm/test.pdf' notoc bookmarkgen=no;
proc sgplot data=test;
    by notsorted formula;
    series x=x y=y / group=formula smoothconnect;
    keylegend / location=outside position=bottom title='';
    xaxis min=0;
    yaxis min=0;
    *where formula='Equation: x**2';
run;
ods pdf close;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 07 Aug 2021 14:46:53 GMT</pubDate>
    <dc:creator>JeffMeyers</dc:creator>
    <dc:date>2021-08-07T14:46:53Z</dc:date>
    <item>
      <title>Multiple legends PROC SGPLOT</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760035#M21798</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am creating a series plot/graph using PROC SGPLOT&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;series x=value y=curve;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;I want to show different equation values on different pages in legend. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;(I do not want to use inset statement as in the legend the equation should appear beside the&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-family: inherit;"&gt;series line)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;I am making different pages for each different value of parameters hence the equation of curve changes.&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Any leads will be appreciated.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Aug 2021 17:45:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760035#M21798</guid>
      <dc:creator>deep_sas</dc:creator>
      <dc:date>2021-08-06T17:45:11Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple legends PROC SGPLOT</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760036#M21799</link>
      <description>&lt;P&gt;Annotate or TEXT statements, assuming you've already explored the KEYLEGEND statement.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Aug 2021 17:51:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760036#M21799</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-08-06T17:51:36Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple legends PROC SGPLOT</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760039#M21801</link>
      <description>&lt;P&gt;Hello, can you use the CURVELABEL option? i.e.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sgplot data=sashelp.stocks&lt;BR /&gt;(where=(date &amp;gt;= "01jan2000"d and stock = "IBM"));&lt;BR /&gt;title "Stock Trend";&lt;BR /&gt;series x=date y=close / curvelabel = "y=x";&lt;BR /&gt;run;&lt;BR /&gt;title;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Aug 2021 17:52:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760039#M21801</guid>
      <dc:creator>djrisks</dc:creator>
      <dc:date>2021-08-06T17:52:46Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple legends PROC SGPLOT</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760064#M21802</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10604"&gt;@djrisks&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have already tried this option but the equation is too large that the plot does not look good.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the suggestion.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Aug 2021 18:42:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760064#M21802</guid>
      <dc:creator>deep_sas</dc:creator>
      <dc:date>2021-08-06T18:42:32Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple legends PROC SGPLOT</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760086#M21803</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please give me an example for ANNOTATE in PROC SGPLOT. I am not how will this work, will it change the value of the equation every time the PAGE of PLOT changes.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Aug 2021 20:31:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760086#M21803</guid>
      <dc:creator>deep_sas</dc:creator>
      <dc:date>2021-08-06T20:31:02Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple legends PROC SGPLOT</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760087#M21804</link>
      <description>Where does the equation come from? You can have SAS generate code via CALL EXECUTE, Macros or DOSUBL. &lt;BR /&gt;I cannot provide a dynamic solution for unseen data structures.</description>
      <pubDate>Fri, 06 Aug 2021 20:36:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760087#M21804</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-08-06T20:36:14Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple legends PROC SGPLOT</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760146#M21807</link>
      <description>Hi, I am aware of the macros and another ways where distinct values can be stored. But I just wanted more information/example on "ANNOTATE" for LEGEND which will change for each page.(I did a lot of searches on the topic for ANNOTATE for LEGEND purposes but did not find anything which was useful for me) Thanks ..!!!</description>
      <pubDate>Sat, 07 Aug 2021 13:00:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760146#M21807</guid>
      <dc:creator>deep_sas</dc:creator>
      <dc:date>2021-08-07T13:00:59Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple legends PROC SGPLOT</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760147#M21808</link>
      <description>Is it possible to give an example of exactly what you want? Even temporarily using a textbox in paint to show it? I'm having a hard time picturing it but it sounds like something I can make.</description>
      <pubDate>Sat, 07 Aug 2021 13:07:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760147#M21808</guid>
      <dc:creator>JeffMeyers</dc:creator>
      <dc:date>2021-08-07T13:07:53Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple legends PROC SGPLOT</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760153#M21809</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="figure.JPG" style="width: 514px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/62369i188E8C90D0634178/image-size/large?v=v2&amp;amp;px=999" role="button" title="figure.JPG" alt="figure.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So I need the legend which is right below the series plot where the "Equation" in legend changes every page. Please Note: I have already tried many options such as : TEXT, INSET,KEYLEGEND etc . I am also aware that the text can be macrotised but I just need an idea for the Different legend which changes on each page.&lt;/P&gt;&lt;P&gt;any information or any leads will be appreciated. Than you.&lt;/P&gt;</description>
      <pubDate>Sat, 07 Aug 2021 14:27:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760153#M21809</guid>
      <dc:creator>deep_sas</dc:creator>
      <dc:date>2021-08-07T14:27:41Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple legends PROC SGPLOT</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760155#M21810</link>
      <description>&lt;P&gt;I just made a group variable with the text you wanted for the equation and then used that as the GROUP statement in the SERIES plot.&amp;nbsp; I can then add that to the legend to get it how you're showing.&amp;nbsp; By then also including that variable in the BY statement I can get one equation per page.&amp;nbsp; You can use the same technique to make one graph at a time as well if you use the WHERE statement I commented out to select one at a time and it'll look the same (but then you can customize individual axes/colors/etc.).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data test;
    length formula $100.;
    
    formula='Equation: x**2';
    do x=0 to 10;
        y=x**2;output;
    end;
    formula='Equation: 2x-5';
    do x=0 to 10;
        y=2*x-5;output;
    end;
    formula='Equation: log(x)';
    do x=0 to 10;
        if x=0 then y=log(0.0001);
        else y=log(x);
        output;
    end;
run;

options nobyline;
ods pdf file='~/ibm/test.pdf' notoc bookmarkgen=no;
proc sgplot data=test;
    by notsorted formula;
    series x=x y=y / group=formula smoothconnect;
    keylegend / location=outside position=bottom title='';
    xaxis min=0;
    yaxis min=0;
    *where formula='Equation: x**2';
run;
ods pdf close;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 07 Aug 2021 14:46:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760155#M21810</guid>
      <dc:creator>JeffMeyers</dc:creator>
      <dc:date>2021-08-07T14:46:53Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple legends PROC SGPLOT</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760156#M21811</link>
      <description>&lt;P&gt;Here is some potential code that you can use.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I created a macro with two arguments, you just need to add the graph, i.e. the parameter and also the equation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data stocks;
  set sashelp.stocks(in=a) sashelp.stocks(in=b);
  if a then do;
	graph = "Graph 1";
  end;
  if b then do;
    close = close + 100 + (close *2);
	graph = "Graph 2";
  end;
run;


%macro legend(equation=, graph=);
title1 #byval1;
proc sgplot data=stocks(where=(date &amp;gt;= "01jan2000"d and stock = "IBM"));
  by graph;
  where graph = "&amp;amp;graph";
  series x=date y=close / name = "leg" legendlabel=" ";
  keylegend "leg" / title = "&amp;amp;equation" type=line;
run;

%mend;
%legend(equation=%str(Y=X), graph=%str(Graph 1));
%legend(equation=%str(Y=100 + 2X), graph=%str(Graph 2));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 07 Aug 2021 14:58:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760156#M21811</guid>
      <dc:creator>djrisks</dc:creator>
      <dc:date>2021-08-07T14:58:49Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple legends PROC SGPLOT</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760161#M21813</link>
      <description>Hi ,&lt;BR /&gt;Thank you for the suggestion but I have total 100 PARAMETERS ie. 100 different equation and 100 pages so I have macrotised PROC SGPLOt rather than calling "%legend" macro 100 times ,though I am aware this can be one of the solution but I am looking for more efficient way.</description>
      <pubDate>Sat, 07 Aug 2021 15:20:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760161#M21813</guid>
      <dc:creator>deep_sas</dc:creator>
      <dc:date>2021-08-07T15:20:49Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple legends PROC SGPLOT</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760162#M21814</link>
      <description>&lt;P&gt;You're welcome. Do you know&amp;nbsp; you can also use CALL EXECUTE to do your macro calls, that way, you don't have to do it yourself 100 times and you can use your data to do it. Another alternative would just be to use the BY variable processing which Jeff showed.&lt;/P&gt;</description>
      <pubDate>Sat, 07 Aug 2021 15:24:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760162#M21814</guid>
      <dc:creator>djrisks</dc:creator>
      <dc:date>2021-08-07T15:24:21Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple legends PROC SGPLOT</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760164#M21815</link>
      <description>&lt;P&gt;This code is incase you are interested in knowing how to do the CALL EXECUTE example...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data stocks;
  set sashelp.stocks(in=a) sashelp.stocks(in=b);
  length equation $20;
  if a then do;
	graph = "Graph 1";
	equation = "Y=X";
  end;
  if b then do;
    close = close + 100 + (close *2);
	graph = "Graph 2";
	equation = "100 + 2X";
  end;
run;

proc sql;
  create table equations as
  select distinct equation, graph
  from stocks
  order by graph;
quit;


%macro legend(equation=, graph=);
title1 #byval1;
proc sgplot data=stocks(where=(date &amp;gt;= "01jan2000"d and stock = "IBM"));
  by graph;
  where graph = "&amp;amp;graph";
  series x=date y=close / name = "leg" legendlabel=" ";
  keylegend "leg" / title = "&amp;amp;equation" type=line;
run;

%mend;

options nobyline;
data _null_;
   set equations;
   call execute('%legend(equation=%str('||equation||'), graph=%str('||graph||'))');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 07 Aug 2021 15:41:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Multiple-legends-PROC-SGPLOT/m-p/760164#M21815</guid>
      <dc:creator>djrisks</dc:creator>
      <dc:date>2021-08-07T15:41:11Z</dc:date>
    </item>
  </channel>
</rss>

