<?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: How to add multiple texts to SGPLOT in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-multiple-texts-to-SGPLOT/m-p/952687#M372308</link>
    <description>&lt;PRE&gt;"Thank you for your help with adding texts into the sgplot.
But I'd also like to know how to remove x and y of the annotation in the legend?
I may have other variables in the data. 
So how to remove x and y of the annotation in the legend 
but keep other variables in the legend? 
The original post can be accessed "&lt;/PRE&gt;
&lt;P&gt;OK. You want this ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Main data set */
data mydata;
    input x y;
    datalines;
    1 10
    2 20
    3 30
    ;
run;

/* Annotation data set */
data annotations;
    input x y text $quote20.;
    datalines;
    1 15 "First Note"
    2 25 "Second Note"
    3 35 "Third Note"
    ;
run;

data have;
 set mydata annotations;
run;

/* Plot with annotations */
proc sgplot data=have;
    scatter x=x y=y /name='x' ; /* Main plot */
    text x=x y=y text=text /strip contributeoffsets=none  ; /* Adding annotations */
	xaxis offsetmin=0.05 offsetmax=0.05;
	keylegend 'x';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1733446577753.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102733i58824E2CE77EFF0D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1733446577753.png" alt="Ksharp_0-1733446577753.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 06 Dec 2024 00:56:24 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2024-12-06T00:56:24Z</dc:date>
    <item>
      <title>How to add multiple texts to SGPLOT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-multiple-texts-to-SGPLOT/m-p/952584#M372280</link>
      <description>&lt;P&gt;I got the SAS code below to add multiple texts to the figure created by sgplot. However, it does not work. Could you help me correct it? Many thanks.&lt;/P&gt;
&lt;PRE&gt;/* Main data set */
data mydata;
    input x y;
    datalines;
    1 10
    2 20
    3 30
    ;
run;

/* Annotation data set */
data annotations;
    input x y text $20.;
    datalines;
    1 15 "First Note"
    2 25 "Second Note"
    3 35 "Third Note"
    ;
run;

/* Plot with annotations */
proc sgplot data=mydata;
    scatter x=x y=y; /* Main plot */
    text x=x y=y text=text / data=annotations; /* Adding annotations */
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 04 Dec 2024 23:42:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-multiple-texts-to-SGPLOT/m-p/952584#M372280</guid>
      <dc:creator>SeaMoon_168</dc:creator>
      <dc:date>2024-12-04T23:42:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to add multiple texts to SGPLOT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-multiple-texts-to-SGPLOT/m-p/952589#M372282</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Main data set */
data mydata;
    input x y;
    datalines;
    1 10
    2 20
    3 30
    ;
run;

/* Annotation data set */
data annotations;
    input x y text $quote20.;
    datalines;
    1 15 "First Note"
    2 25 "Second Note"
    3 35 "Third Note"
    ;
run;

data have;
 set mydata annotations;
run;

/* Plot with annotations */
proc sgplot data=have;
    scatter x=x y=y; /* Main plot */
    text x=x y=y text=text /strip contributeoffsets=none; /* Adding annotations */
	xaxis offsetmin=0.05 offsetmax=0.05;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1733361000543.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102720iE25DB398C1B5D775/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1733361000543.png" alt="Ksharp_0-1733361000543.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2024 01:10:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-multiple-texts-to-SGPLOT/m-p/952589#M372282</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-12-05T01:10:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to add multiple texts to SGPLOT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-multiple-texts-to-SGPLOT/m-p/952592#M372284</link>
      <description>&lt;P&gt;Awesome, Many thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2024 01:51:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-multiple-texts-to-SGPLOT/m-p/952592#M372284</guid>
      <dc:creator>SeaMoon_168</dc:creator>
      <dc:date>2024-12-05T01:51:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to add multiple texts to SGPLOT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-multiple-texts-to-SGPLOT/m-p/952660#M372293</link>
      <description>&lt;P&gt;Thanks but how to remove x and y of the annotation in the legend? I may have other variables in the data. So how to remove x and y of the annotation in the legend but keep other variables in the legend?&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2024 19:03:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-multiple-texts-to-SGPLOT/m-p/952660#M372293</guid>
      <dc:creator>SeaMoon_168</dc:creator>
      <dc:date>2024-12-05T19:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to add multiple texts to SGPLOT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-multiple-texts-to-SGPLOT/m-p/952661#M372294</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/382088"&gt;@SeaMoon_168&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks but how to remove x and y of the annotation in the legend? I may have other variables in the data. So how to remove x and y of the annotation in the legend but keep other variables in the legend?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You need to show the exact code you are using.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Legend appearance is controlled by the Keylegend options.&lt;/P&gt;
&lt;P&gt;If by "other variables" you mean you have multiple plots using other variables then the approach is to provide a NAME for each plot and then the Keylegend statement lists the names of the specific plot that you want included in the legend.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;proc sgpanel data=sashelp.class noautolegend;
  panelby sex;
  histogram height /name='hist';
  density height /
    type=kernel
    name="kernel"
    lineattrs=(color = red);
  keylegend "kernel" /
    title="Density Plot"
    titleattrs=(color = red);
run;&lt;/PRE&gt;
&lt;P&gt;The name for the histogram isn't required but shown as an example. The only legend that will appear is for the Density plot with the name "kernel".&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2024 19:19:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-multiple-texts-to-SGPLOT/m-p/952661#M372294</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-12-05T19:19:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to add multiple texts to SGPLOT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-multiple-texts-to-SGPLOT/m-p/952687#M372308</link>
      <description>&lt;PRE&gt;"Thank you for your help with adding texts into the sgplot.
But I'd also like to know how to remove x and y of the annotation in the legend?
I may have other variables in the data. 
So how to remove x and y of the annotation in the legend 
but keep other variables in the legend? 
The original post can be accessed "&lt;/PRE&gt;
&lt;P&gt;OK. You want this ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Main data set */
data mydata;
    input x y;
    datalines;
    1 10
    2 20
    3 30
    ;
run;

/* Annotation data set */
data annotations;
    input x y text $quote20.;
    datalines;
    1 15 "First Note"
    2 25 "Second Note"
    3 35 "Third Note"
    ;
run;

data have;
 set mydata annotations;
run;

/* Plot with annotations */
proc sgplot data=have;
    scatter x=x y=y /name='x' ; /* Main plot */
    text x=x y=y text=text /strip contributeoffsets=none  ; /* Adding annotations */
	xaxis offsetmin=0.05 offsetmax=0.05;
	keylegend 'x';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1733446577753.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/102733i58824E2CE77EFF0D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1733446577753.png" alt="Ksharp_0-1733446577753.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Dec 2024 00:56:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-multiple-texts-to-SGPLOT/m-p/952687#M372308</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-12-06T00:56:24Z</dc:date>
    </item>
  </channel>
</rss>

