<?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: SGPlot and Curvelabel positioning in Graphics Programming</title>
    <link>https://communities.sas.com/t5/Graphics-Programming/SGPlot-and-Curvelabel-positioning/m-p/960037#M25293</link>
    <description>&lt;P&gt;Is there a reason you're writing separate SERIES statements instead of writing a single SERIES statement with the GROUP= option?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 24 Feb 2025 00:45:32 GMT</pubDate>
    <dc:creator>quickbluefish</dc:creator>
    <dc:date>2025-02-24T00:45:32Z</dc:date>
    <item>
      <title>SGPlot and Curvelabel positioning</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPlot-and-Curvelabel-positioning/m-p/959980#M25286</link>
      <description>&lt;P&gt;I want to position some curvelabels at the end of my time-series lines. I'm trying different combinations of CURVELABELLOC and CURVELABELPOS.&lt;/P&gt;
&lt;P&gt;For some reason, it keeps on putting the label for the top series on top of the figure. The first figure is with&lt;/P&gt;
&lt;P&gt;OUTSIDE and MAX (same results with AUTO). The second is with INSIDE and MAX. (If I drop the top series, I some of the labels on the top and rotated!).&lt;/P&gt;
&lt;P&gt;How can I force it to put all labels down the RHS of the figure?&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="BruceBrad_0-1740183180037.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/104851i0AD7BDF1671A67DC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BruceBrad_0-1740183180037.png" alt="BruceBrad_0-1740183180037.png" /&gt;&lt;/span&gt;&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="BruceBrad_1-1740183449334.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/104852i2F77DC6C5CA05301/image-size/medium?v=v2&amp;amp;px=400" role="button" title="BruceBrad_1-1740183449334.png" alt="BruceBrad_1-1740183449334.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Feb 2025 00:29:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPlot-and-Curvelabel-positioning/m-p/959980#M25286</guid>
      <dc:creator>BruceBrad</dc:creator>
      <dc:date>2025-02-22T00:29:07Z</dc:date>
    </item>
    <item>
      <title>Re: SGPlot and Curvelabel positioning</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPlot-and-Curvelabel-positioning/m-p/959981#M25287</link>
      <description>One more point: This behaviour is probably driven by the fact that some of the series finish earlier than the others. I've also tried INSIDE and END, which sort of works for positioning, but the labels then overprint other series datapoints.</description>
      <pubDate>Sat, 22 Feb 2025 00:50:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPlot-and-Curvelabel-positioning/m-p/959981#M25287</guid>
      <dc:creator>BruceBrad</dc:creator>
      <dc:date>2025-02-22T00:50:44Z</dc:date>
    </item>
    <item>
      <title>Re: SGPlot and Curvelabel positioning</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPlot-and-Curvelabel-positioning/m-p/959983#M25288</link>
      <description>Post your data and code to replicate your problem.&lt;BR /&gt;So could help to address where is problem.</description>
      <pubDate>Sat, 22 Feb 2025 02:11:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPlot-and-Curvelabel-positioning/m-p/959983#M25288</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-02-22T02:11:13Z</dc:date>
    </item>
    <item>
      <title>Re: SGPlot and Curvelabel positioning</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPlot-and-Curvelabel-positioning/m-p/960035#M25291</link>
      <description>&lt;P&gt;My code has lots of lines, but this simple code shows the problem. My preference would be to have all the labels on the outside at right.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dat;
input date var1 var2;
cards;
1 10 20
2 10 20
3 10 .
4 10 .
;
run;
Title "Outside puts one series at top (I would prefer all the labels at right)";
proc sgplot;
series x=date y=var1 /curvelabel curvelabelloc=outside;
series x=date y=var2 /curvelabel curvelabelloc=outside;
run;
title "Inside, in this case, works OK";
title2 "Though the top label would be neater if it were to the right";
proc sgplot;
series x=date y=var1 /curvelabel curvelabelloc=inside curvelabelpos=max;
series x=date y=var2 /curvelabel curvelabelloc=inside curvelabelpos=max;
run;
title "However, if the lines are close together, one label gets put at the bottom";
proc sgplot;
series x=date y=var1 /curvelabel curvelabelloc=inside curvelabelpos=max;
series x=date y=var2 /curvelabel curvelabelloc=inside curvelabelpos=max;
yaxis values=(1 to 100);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 23 Feb 2025 23:30:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPlot-and-Curvelabel-positioning/m-p/960035#M25291</guid>
      <dc:creator>BruceBrad</dc:creator>
      <dc:date>2025-02-23T23:30:05Z</dc:date>
    </item>
    <item>
      <title>Re: SGPlot and Curvelabel positioning</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPlot-and-Curvelabel-positioning/m-p/960036#M25292</link>
      <description>&lt;P&gt;Here is a work-around. I create two dummy cases at the end. But this wouldn't work if I had data point markers.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* Curvelabel;
data dat;
input date var1 var2;
cards;
1 10 20
2 15 25
3 11 .
4 18 .
;
run;
data dat2;
retain retainvar1 retainvar2;
drop retainvar1 retainvar2;
set dat end=lastobs;
if not(missing(var1)) then retainvar1 = var1;
if not(missing(var2)) then retainvar2 = var2;
output;
nextdate = lag(date)+1;
nextdate2 = lag(date)+2;
drop nextdate nextdate2;
if lastobs then do;
  date = nextdate;
  var1 = .;
  var2 = .;
  output;
  date = nextdate2;
  var1 = retainvar1;
  var2 = retainvar2;
  output;
end;
run;

Title "Adding two dummy observations at end works if I don't have data point markers";
proc sgplot data=dat2;
series x=date y=var1 /curvelabel curvelabelloc=outside break;
series x=date y=var2 /curvelabel curvelabelloc=outside break;
run;
title;
proc sgplot data=dat2;
series x=date y=var1 /curvelabel curvelabelloc=inside curvelabelpos=max break;
series x=date y=var2 /curvelabel curvelabelloc=inside curvelabelpos=max break;
run;

proc sgplot data=dat2;
series x=date y=var1 /curvelabel curvelabelloc=inside curvelabelpos=max break;
series x=date y=var2 /curvelabel curvelabelloc=inside curvelabelpos=max break;
yaxis values=(1 to 100);
run;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Feb 2025 00:43:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPlot-and-Curvelabel-positioning/m-p/960036#M25292</guid>
      <dc:creator>BruceBrad</dc:creator>
      <dc:date>2025-02-24T00:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: SGPlot and Curvelabel positioning</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPlot-and-Curvelabel-positioning/m-p/960037#M25293</link>
      <description>&lt;P&gt;Is there a reason you're writing separate SERIES statements instead of writing a single SERIES statement with the GROUP= option?&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2025 00:45:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPlot-and-Curvelabel-positioning/m-p/960037#M25293</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-02-24T00:45:32Z</dc:date>
    </item>
    <item>
      <title>Re: SGPlot and Curvelabel positioning</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPlot-and-Curvelabel-positioning/m-p/960039#M25294</link>
      <description>Mainly just habit. This allows me to customise the appearance of each line manually. Would reshaping the data and using groups force a line-up of the labels?</description>
      <pubDate>Mon, 24 Feb 2025 00:52:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPlot-and-Curvelabel-positioning/m-p/960039#M25294</guid>
      <dc:creator>BruceBrad</dc:creator>
      <dc:date>2025-02-24T00:52:28Z</dc:date>
    </item>
    <item>
      <title>Re: SGPlot and Curvelabel positioning</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPlot-and-Curvelabel-positioning/m-p/960043#M25295</link>
      <description>&lt;P&gt;Agree this is odd - especially the ones that show up on the bottom when the lines are close together.&amp;nbsp; At least for the ones that place the label on top, I think the algorithm is just trying to put it in the least ambiguous position possible, even if it doesn't look great.&amp;nbsp; It's more obvious when you have a lot of lines, some of which (like in your plot) only extend part way down the x-axis:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="quickbluefish_1-1740359584938.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/104878iD98A9CD2404DBD33/image-size/medium?v=v2&amp;amp;px=400" role="button" title="quickbluefish_1-1740359584938.png" alt="quickbluefish_1-1740359584938.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;You could play around with something like this instead -- labeling with the TEXT statement instead of the CURVELABEL options:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
do grp=1 to 10;
	ymean=rand('erlang',2)*5;
	nwks=25;
	if ranuni(0)&amp;lt;0.4 then nwks=rand('integer',5,25);
	x=.; y=.;
	do wk=1 to nwks;
		yval=ymean+rand('normal')*10;
		if wk=nwks then do;
			put 'hello?';
			x=wk;
			y=yval;
		end;
		output;
	end;
end;
run;

proc sgplot data=test noautolegend;
series x=wk y=yval / group=grp;
text x=x y=y text=grp / group=grp textattrs=(size=12pt) position=right backfill backlight;
scatter x=x y=y / group=grp markerattrs=(size=12pt);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="quickbluefish_2-1740360460753.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/104879iDA58CD6D59AC7FD0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="quickbluefish_2-1740360460753.png" alt="quickbluefish_2-1740360460753.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Looks a little silly as-is, but if you fiddle with the options, I would bet you can get something good.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2025 01:28:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPlot-and-Curvelabel-positioning/m-p/960043#M25295</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-02-24T01:28:28Z</dc:date>
    </item>
    <item>
      <title>Re: SGPlot and Curvelabel positioning</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPlot-and-Curvelabel-positioning/m-p/960045#M25296</link>
      <description>&lt;P&gt;You want this ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;* Curvelabel;
data dat;
input date var1 var2;
cards;
1 10 20
2 15 25
3 11 .
4 18 .
;
run;
data dat2;
set dat end=last;
retain retainvar1 retainvar2;
if not missing(var1) then retainvar1=var1;
if not missing(var2) then retainvar2=var2;
if last;
keep date retainvar1 retainvar2;
run;
%sganno
data sganno;
 set dat2;
 %SGTEXT(LABEL='var1',WIDTH=80, X1SPACE="GRAPHPERCENT",Y1SPACE="DATAVALUE" ,X1=96,Y1=retainvar1,TEXTCOLOR="blue")
 %SGTEXT(LABEL='var2',WIDTH=80, X1SPACE="GRAPHPERCENT",Y1SPACE="DATAVALUE" ,X1=96,Y1=retainvar2,TEXTCOLOR="red")
run;

proc sgplot data=dat sganno=sganno ;
series x=date y=var1 /markers markerattrs=(symbol=circlefilled color=blue) lineattrs=(color=blue)
 CURVELABELLOC=outside curvelabel curvelabelattrs=(color=white);
series x=date y=var2 /markers markerattrs=(symbol=circlefilled color=red) lineattrs=(color=red) 
 CURVELABELLOC=outside curvelabel curvelabelattrs=(color=white);
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-1740362749709.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/104880i4AED582206D2E6C0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1740362749709.png" alt="Ksharp_0-1740362749709.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2025 02:24:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPlot-and-Curvelabel-positioning/m-p/960045#M25296</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-02-24T02:24:35Z</dc:date>
    </item>
    <item>
      <title>Re: SGPlot and Curvelabel positioning</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPlot-and-Curvelabel-positioning/m-p/960072#M25300</link>
      <description>&lt;P&gt;Thanks everyone for all the suggestions. I'll have to learn how to do annotations. SAS is obviously looking at which axis is closest to the max point for each line and putting the label on that axis. Unfortunately this is often pretty ugly.&lt;/P&gt;
&lt;P&gt;One simple enhancement for SAS would be to add an OUTSIDERIGHT choice to the CURVELABELLOC option to allow users to force output to the right hand side.&lt;/P&gt;
&lt;P&gt;A very simple work-around (which is actually workable for my graph today) is to change the y axis to have more white space at top and bottom - then the right axis will always be closer.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Feb 2025 11:20:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPlot-and-Curvelabel-positioning/m-p/960072#M25300</guid>
      <dc:creator>BruceBrad</dc:creator>
      <dc:date>2025-02-24T11:20:15Z</dc:date>
    </item>
    <item>
      <title>Re: SGPlot and Curvelabel positioning</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPlot-and-Curvelabel-positioning/m-p/960089#M25301</link>
      <description>&lt;P&gt;I maybe END instead of max&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data dat;
input date var1 var2;
cards;
1 10 20
2 15 25
3 11 .
4 18 .
;
run;
data dat2;
retain retainvar1 retainvar2;
drop retainvar1 retainvar2;
set dat end=lastobs;
if not(missing(var1)) then retainvar1 = var1;
if not(missing(var2)) then retainvar2 = var2;
output;
nextdate = lag(date)+1;
nextdate2 = lag(date)+2;
drop nextdate nextdate2;
if lastobs then do;
  date = nextdate;
  var1 = .;
  var2 = .;
  output;
  date = nextdate2;
  var1 = retainvar1;
  var2 = retainvar2;
  output;
end;
run;

title "Curvelabelpos=END with outside";
proc sgplot data=dat2;
series x=date y=var1 /curvelabel curvelabelloc=outside curvelabelpos=end break;
series x=date y=var2 /curvelabel curvelabelloc=outside curvelabelpos=end break;
run;

title "Curvelabelpos=END with inside";
proc sgplot data=dat2;
series x=date y=var1 /curvelabel curvelabelloc=inside curvelabelpos=end break;
series x=date y=var2 /curvelabel curvelabelloc=inside curvelabelpos=end break;
run;
title;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Feb 2025 14:52:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPlot-and-Curvelabel-positioning/m-p/960089#M25301</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2025-02-24T14:52:35Z</dc:date>
    </item>
    <item>
      <title>Re: SGPlot and Curvelabel positioning</title>
      <link>https://communities.sas.com/t5/Graphics-Programming/SGPlot-and-Curvelabel-positioning/m-p/960094#M25302</link>
      <description>&lt;P&gt;That looks promising.&amp;nbsp; Can you make the dots disappear?&lt;/P&gt;
&lt;P&gt;It might be easier to make them disappear if they were generated by separate statements.&amp;nbsp; That will also make the data manipulation easier.&lt;/P&gt;
&lt;P&gt;Like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dat3;
retain retainvar1 retainvar2;
set dat end=lastobs;
if not(missing(var1)) then retainvar1 = var1;
if not(missing(var2)) then retainvar2 = var2;
output;
if lastobs then do;
  var1 = .;
  var2 = .;
  var1e = retainvar1;
  var2e = retainvar2;
  output;
end;
drop retainvar1 retainvar2;
run;

title "Curvelabelpos=END with outside";
proc sgplot data=dat3;
series x=date y=var1 / ;
series x=date y=var2 / ;
series x=date y=var1e /curvelabel curvelabelloc=outside curvelabelpos=end ;
series x=date y=var2e /curvelabel curvelabelloc=outside curvelabelpos=end ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Feb 2025 15:50:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Graphics-Programming/SGPlot-and-Curvelabel-positioning/m-p/960094#M25302</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-02-24T15:50:14Z</dc:date>
    </item>
  </channel>
</rss>

