<?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: Label Maximum Value Only on Scatterplot in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/Label-Maximum-Value-Only-on-Scatterplot/m-p/453795#M15563</link>
    <description>&lt;P&gt;Thanks for the reply! I found an approach that worked, I think my use of if / then syntax needs some practice because the same approach was not working until I added do / end.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not familiar with sganno,&amp;nbsp;i'm trying to find an example of case where&amp;nbsp;it is used to apply an annotation only to the maximum value. I don't suppose you would know of an example, or&amp;nbsp;a source I can read?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;An approach I have that seems to work, given the&amp;nbsp;variable names from my previous post as 'colorindex', 'color', 'colorscore' in that order, and being in the dataset 'mydata':&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;*Sort on color score;
proc sort data=mydata;
	by descending score;
run;

*create new variable 'colorwithhighestscore' on row 1 with 'if _n_ = 1 then' 
(known highest value) only, force blank for all other rows with new variable;
data mydata;
	set mydata;
	if _n_ = 1 then
	do;
		colorwithhighestscore = color;
	end;
	else
	do;
		colorwithhighestscore = "";
	end;
run;

*plot using new variable 'colorwithhighestscore' as label;
proc sgplot data=mydata;
	scatter x=colorindex y=colorscore / datalabel=colorwithhighestscore;
run;&lt;/PRE&gt;&lt;P&gt;I'm not sure this is the best approach, only an approach that I could make work. Feedback is very welcome.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks in advance!&lt;/P&gt;</description>
    <pubDate>Thu, 12 Apr 2018 23:46:49 GMT</pubDate>
    <dc:creator>Scottmeup</dc:creator>
    <dc:date>2018-04-12T23:46:49Z</dc:date>
    <item>
      <title>Label Maximum Value Only on Scatterplot</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Label-Maximum-Value-Only-on-Scatterplot/m-p/453417#M15547</link>
      <description>&lt;P&gt;Hi! I've been trying to figure out how to label&amp;nbsp;only a maximum value on a scatterplot by a value from another column in that observation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;eg. with the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;1 Yellow 3
2 Red 5
3 Blue 16
4 Purple 2
5 Orange 5&lt;/PRE&gt;&lt;P&gt;I would use column 1 as the x variable, column 3 as the y variable and in the case of "3 Blue 16" I would like the point to be displayed as "Blue" on the plot and the rest of the data points as the default style.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried a few methods (links below) which _do_ find the maximum value, but I haven't been able to make use of that information with a plot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.sas.com/t5/General-SAS-Programming/Fastest-way-to-calculate-the-max-of-a-variable-in-a-large/td-p/247674" target="_blank"&gt;https://communities.sas.com/t5/General-SAS-Programming/Fastest-way-to-calculate-the-max-of-a-variable-in-a-large/td-p/247674&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/Maximum-value-of-a-column-variable/td-p/28751" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/Maximum-value-of-a-column-variable/td-p/28751&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried storing a local variable with the maximum, and only labelling that through&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;if column3 = maximum_value then scatterplot x=column1 y=column2 / datalabel=column2;
else  scatterplot x=column1 y=column2;&lt;/PRE&gt;&lt;P&gt;But haven't been able to make that work, and thinking about it might not be the best method: the axis are probably not going to align by default if nothing else.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My other approach was to create a column4, and setting it to = column2 if column3's value is the maximum of the column, or blank if that observation's column3 value is not the maximum but I don't seem to be having any success. I don't think I know the syntax well enough.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know a way I can dynamically calculate the maximum of column3, store that and use&amp;nbsp;the information to label the relevant plot point with the value for column2 ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 00:27:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Label-Maximum-Value-Only-on-Scatterplot/m-p/453417#M15547</guid>
      <dc:creator>Scottmeup</dc:creator>
      <dc:date>2018-04-12T00:27:58Z</dc:date>
    </item>
    <item>
      <title>Re: Label Maximum Value Only on Scatterplot</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Label-Maximum-Value-Only-on-Scatterplot/m-p/453610#M15553</link>
      <description>&lt;P&gt;It would help to show the entire code you are using to generate your graph. The snippet you show implies that you are using GTL and incorporating methods for such a task might require changes to either the template or the sgrender code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Probably the most flexible to display a single value would be to add an SGANNO= annotate data set but that requires having the appropriate ANNOTATE statements in the template.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 15:28:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Label-Maximum-Value-Only-on-Scatterplot/m-p/453610#M15553</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-04-12T15:28:12Z</dc:date>
    </item>
    <item>
      <title>Re: Label Maximum Value Only on Scatterplot</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Label-Maximum-Value-Only-on-Scatterplot/m-p/453795#M15563</link>
      <description>&lt;P&gt;Thanks for the reply! I found an approach that worked, I think my use of if / then syntax needs some practice because the same approach was not working until I added do / end.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not familiar with sganno,&amp;nbsp;i'm trying to find an example of case where&amp;nbsp;it is used to apply an annotation only to the maximum value. I don't suppose you would know of an example, or&amp;nbsp;a source I can read?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;An approach I have that seems to work, given the&amp;nbsp;variable names from my previous post as 'colorindex', 'color', 'colorscore' in that order, and being in the dataset 'mydata':&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;*Sort on color score;
proc sort data=mydata;
	by descending score;
run;

*create new variable 'colorwithhighestscore' on row 1 with 'if _n_ = 1 then' 
(known highest value) only, force blank for all other rows with new variable;
data mydata;
	set mydata;
	if _n_ = 1 then
	do;
		colorwithhighestscore = color;
	end;
	else
	do;
		colorwithhighestscore = "";
	end;
run;

*plot using new variable 'colorwithhighestscore' as label;
proc sgplot data=mydata;
	scatter x=colorindex y=colorscore / datalabel=colorwithhighestscore;
run;&lt;/PRE&gt;&lt;P&gt;I'm not sure this is the best approach, only an approach that I could make work. Feedback is very welcome.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Thanks in advance!&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 23:46:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Label-Maximum-Value-Only-on-Scatterplot/m-p/453795#M15563</guid>
      <dc:creator>Scottmeup</dc:creator>
      <dc:date>2018-04-12T23:46:49Z</dc:date>
    </item>
    <item>
      <title>Re: Label Maximum Value Only on Scatterplot</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/Label-Maximum-Value-Only-on-Scatterplot/m-p/453923#M15566</link>
      <description>&lt;P&gt;Here's one way to do it, using Proc Gplot, and pointlabel ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data mydata;&lt;BR /&gt;length color $10;&lt;BR /&gt;input X color Score;&lt;BR /&gt;datalines;&lt;BR /&gt;1 Yellow 3&lt;BR /&gt;2 Red 5&lt;BR /&gt;3 Blue 16&lt;BR /&gt;4 Purple 2&lt;BR /&gt;5 Orange 5&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc sort data=mydata out=mydata;&lt;BR /&gt;by descending score;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data mydata; set mydata;&lt;BR /&gt;if _n_ = 1 then label_text=color;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;symbol1 value=circle height=3pct color=gray55 pointlabel=("#label_text");&lt;/P&gt;
&lt;P&gt;axis1 order=(0 to 20 by 5) minor=none offset=(0,0);&lt;BR /&gt;axis2 minor=none offset=(3,3);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc gplot data=mydata;&lt;BR /&gt;plot score*x / vaxis=axis1 haxis=axis2;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="pointlabel.png" style="width: 821px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/19773i47C4592BF290896A/image-dimensions/821x616?v=v2" width="821" height="616" role="button" title="pointlabel.png" alt="pointlabel.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 14:18:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/Label-Maximum-Value-Only-on-Scatterplot/m-p/453923#M15566</guid>
      <dc:creator>GraphGuy</dc:creator>
      <dc:date>2018-04-13T14:18:44Z</dc:date>
    </item>
  </channel>
</rss>

