<?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: Only display data label once when value is the same for both series in Proc sgplot SAS 9.4 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Only-display-data-label-once-when-value-is-the-same-for-both/m-p/954738#M372856</link>
    <description>&lt;P&gt;The reason this is challenging is because you're trying to use the same variable for the datalabel and the Y position.&amp;nbsp;One thing you could do is disentangle these from each other by making a separate variable for these two - e.g., &amp;amp;Y2 and &amp;amp;Y2label&amp;nbsp; (writing it this way because you seem to be specifying these as macro variables in your code).&amp;nbsp; Then, depending on how your data are set up, you could set Y&amp;lt;n&amp;gt;label to missing for any situation where, for a given value of X, you have duplicate values of Y*.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, I think you could solve this more directly by only having ONE series statement and using the GROUP= argument to differentiate the series plots.&amp;nbsp; &amp;nbsp;That's the whole intent of GROUP option.&amp;nbsp; &amp;nbsp;That said, there are situations where doing it this way is limiting in some way.&amp;nbsp; Let us know whether using GROUP helps.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that doing it with GROUP means that you only have one variable for X, one for Y and one for datalabel (though I think in this case you could just use Y for the datalabel).&amp;nbsp; The key difference vs. what you're currently doing is that the data for the different series plots (in your case, 2) are on *separate rows* of your input dataset, and you add some variable (let's just call it GRP) that delineates the data for the different groups:&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data for_plot;
infile cards dsd truncover firstobs=1 dlm=',';
length X Y 8 GRP $1;
input X Y GRP;
cards;
1,3.7,A
1,4.5,B
2,1.8,A
2,0.0,B
3,5.1,A
3,3.6,B
;
run;

proc sgplot data=for_plot;
series x=X y=Y / group=GRP datalabel=Y;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 30 Dec 2024 00:56:30 GMT</pubDate>
    <dc:creator>quickbluefish</dc:creator>
    <dc:date>2024-12-30T00:56:30Z</dc:date>
    <item>
      <title>Only display data label once when value is the same for both series in Proc sgplot SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Only-display-data-label-once-when-value-is-the-same-for-both/m-p/954735#M372855</link>
      <description>&lt;P&gt;Is there a way I can only show the data label for one series when the data point is the same value for both series?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example, if both series have a value of 0% for the same month, I only want to show the 0% once.&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="Whitlea_3-1735501251474.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/103399iB8C0A79E20D3A3D0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Whitlea_3-1735501251474.png" alt="Whitlea_3-1735501251474.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Here is my proc sgplot code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sgplot data=final noborder ;  

series x=date y=&amp;amp;y1/ datalabel=&amp;amp;y1 DATALABELATTRS=(family='Roboto' SIZE=10pt weight=bold color=black)DATALABELPOS=top
MARKERS MARKERATTRS=(SYMBOL=CircleFilled color=red size=8) LINEATTRS = (color=red pattern=solid THICKNESS=3) legendlabel= "A" ;

series x=date y=&amp;amp;y2 / datalabel=&amp;amp;y2 DATALABELATTRS=(family='Roboto' SIZE=10pt color=black)DATALABELPOS=bottom
MARKERS MARKERATTRS=(SYMBOL=CircleFilled color=blue size=8) LINEATTRS = (color=blue pattern=solid THICKNESS=3) legendlabel= "B";

yaxis  grid VALUES = (&amp;amp;values) display=(noline noticks) valueATTRS=(family='Roboto' size=10pt)
label=" " LABELATTRS=(family='Roboto' size=10pt);

XAXIS TYPE = LINEAR  display=( noline noticks)label=" "
LABELATTRS=(family='Roboto' size=10pt ) valueATTRS=(family='Roboto' size=10pt ) ;


keylegend "A" / noborder location=outside position=bottom   valueATTRS=(family='Roboto' size=10pt weight=bold)  ;

keylegend "B" / noborder location=outside position=bottom  valueATTRS=(family='Roboto' size=10pt);
title &amp;amp;TITLE1 ;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;Thank you!&lt;/P&gt;</description>
      <pubDate>Sun, 29 Dec 2024 19:44:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Only-display-data-label-once-when-value-is-the-same-for-both/m-p/954735#M372855</guid>
      <dc:creator>Whitlea</dc:creator>
      <dc:date>2024-12-29T19:44:53Z</dc:date>
    </item>
    <item>
      <title>Re: Only display data label once when value is the same for both series in Proc sgplot SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Only-display-data-label-once-when-value-is-the-same-for-both/m-p/954738#M372856</link>
      <description>&lt;P&gt;The reason this is challenging is because you're trying to use the same variable for the datalabel and the Y position.&amp;nbsp;One thing you could do is disentangle these from each other by making a separate variable for these two - e.g., &amp;amp;Y2 and &amp;amp;Y2label&amp;nbsp; (writing it this way because you seem to be specifying these as macro variables in your code).&amp;nbsp; Then, depending on how your data are set up, you could set Y&amp;lt;n&amp;gt;label to missing for any situation where, for a given value of X, you have duplicate values of Y*.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, I think you could solve this more directly by only having ONE series statement and using the GROUP= argument to differentiate the series plots.&amp;nbsp; &amp;nbsp;That's the whole intent of GROUP option.&amp;nbsp; &amp;nbsp;That said, there are situations where doing it this way is limiting in some way.&amp;nbsp; Let us know whether using GROUP helps.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that doing it with GROUP means that you only have one variable for X, one for Y and one for datalabel (though I think in this case you could just use Y for the datalabel).&amp;nbsp; The key difference vs. what you're currently doing is that the data for the different series plots (in your case, 2) are on *separate rows* of your input dataset, and you add some variable (let's just call it GRP) that delineates the data for the different groups:&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data for_plot;
infile cards dsd truncover firstobs=1 dlm=',';
length X Y 8 GRP $1;
input X Y GRP;
cards;
1,3.7,A
1,4.5,B
2,1.8,A
2,0.0,B
3,5.1,A
3,3.6,B
;
run;

proc sgplot data=for_plot;
series x=X y=Y / group=GRP datalabel=Y;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2024 00:56:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Only-display-data-label-once-when-value-is-the-same-for-both/m-p/954738#M372856</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2024-12-30T00:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: Only display data label once when value is the same for both series in Proc sgplot SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Only-display-data-label-once-when-value-is-the-same-for-both/m-p/954739#M372857</link>
      <description>&lt;P&gt;OK, I lied - turns out the GROUP= option doesn't appear to solve your original issue, which is to avoid showing the duplicate Y* values in the plot labels.&amp;nbsp; Try this instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data for_plot;
infile cards dsd truncover firstobs=1 dlm=',';
length X Y1 Y2 8;
input X Y1 Y2;
cards;
1,3.8,4.2
2,0,0
3,2.6,3.7
4,3.1,5.6
;
run;

data for_plot;
set for_plot;
Y1lab=Y1; 
Y2lab=Y2;
if Y1=Y2 then Y2lab=.;
run;

proc sgplot data=for_plot;
series x=X y=Y1 / datalabel=Y1lab;
series x=X y=Y2 / datalabel=Y2lab;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Dec 2024 01:05:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Only-display-data-label-once-when-value-is-the-same-for-both/m-p/954739#M372857</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2024-12-30T01:05:18Z</dc:date>
    </item>
  </channel>
</rss>

