<?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: Overlay Series With Regression/Trend Lines for Different (Half) Series using PROC SGPLOT in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Overlay-Series-With-Regression-Trend-Lines-for-Different-Half/m-p/844741#M333963</link>
    <description>&lt;P&gt;I previously only sorted&amp;nbsp; &amp;nbsp;"by monthyear", sorting by&amp;nbsp;"by period monthyear" does the trick.&amp;nbsp;Thank you very much.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 17 Nov 2022 02:19:00 GMT</pubDate>
    <dc:creator>adejames2000</dc:creator>
    <dc:date>2022-11-17T02:19:00Z</dc:date>
    <item>
      <title>Overlay Series With Regression/Trend Lines for Different (Half) Series using PROC SGPLOT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlay-Series-With-Regression-Trend-Lines-for-Different-Half/m-p/844729#M333958</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;I am trying to lay a regression line on each of two different (half) series covering different times of period.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
    create table have as
        select date
             , region
             , sum(sale) as sale
        from sashelp.pricedata
        group by region, date
        order by region, date
    ;
quit;

data have2;
	set have (rename=(region=period));
	if period=3 then delete;
	if period=2 then monthyear=intnx('year',date,5, "sameday");
		else monthyear=date;
	drop date;
	format monthyear monyy5.;
run;

/*CODE 1 PRODUCES SERIES AS EXPECTED*/
proc sgplot data=have2;
    series x=monthyear y=sale / group=period markers;&lt;BR /&gt;    label period="PERIOD";
run;

/*CODE 2 PRODUCES REGRESSION LINE AS EXPECTED*/
proc sgplot data=have2;
    reg x=monthyear y=sale / group=period ;&lt;BR /&gt;    label period="PERIOD";
run;

/*CODE 3 DOES NOT PRODUCES SERIES OVERLAID WITH REGRESSION LINE*/
*When I add the regression line, all the series line are all over the place;
proc sgplot data=have2;
    series x=monthyear y=sale / group=period markers;* markerattrs=(color=lightgreen size=10 symbol=trianglefilled);
	 reg x=monthyear y=sale / group=period ;&lt;BR /&gt;    label period="PERIOD";
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I saw a &lt;A href="https://communities.sas.com/t5/SAS-Programming/Adding-a-trend-line-to-a-series-plot-proc-sgplot/m-p/825408" target="_blank" rel="noopener"&gt;similar example here&lt;/A&gt; but it doesn't work for me, presumably because the periods do not overlap.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is the plot obtained from CODE 1, I just need to have the regression lines through EACH (half) series without distorting the series as CODE 3 does.&lt;/P&gt;&lt;P&gt;Please help, thank you!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Series without regression line.png" style="width: 640px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77374iA4DFFD5839AD1D37/image-size/large?v=v2&amp;amp;px=999" role="button" title="Series without regression line.png" alt="Series without regression line.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 00:00:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlay-Series-With-Regression-Trend-Lines-for-Different-Half/m-p/844729#M333958</guid>
      <dc:creator>adejames2000</dc:creator>
      <dc:date>2022-11-17T00:00:16Z</dc:date>
    </item>
    <item>
      <title>Re: Overlay Series With Regression/Trend Lines for Different (Half) Series using PROC SGPLOT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlay-Series-With-Regression-Trend-Lines-for-Different-Half/m-p/844740#M333962</link>
      <description>&lt;P&gt;Try forcing a sort prior to the last Sgplot and see if that helps. It did on my system (Thank you for using a set we have access to).&lt;/P&gt;
&lt;P&gt;I an guessing that without the specified sort order that mixing Reg with series brings up some internal question about "order", which is typically the cause of that type of connections in a series plot.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sort data=have2;
   by period monthyear;
run;

proc sgplot data=have2;
    series x=monthyear y=sale / group=period markers;* markerattrs=(color=lightgreen size=10 symbol=trianglefilled);
	 reg x=monthyear y=sale / group=period ;
    label period="PERIOD";
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Nov 2022 01:45:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlay-Series-With-Regression-Trend-Lines-for-Different-Half/m-p/844740#M333962</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-11-17T01:45:39Z</dc:date>
    </item>
    <item>
      <title>Re: Overlay Series With Regression/Trend Lines for Different (Half) Series using PROC SGPLOT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Overlay-Series-With-Regression-Trend-Lines-for-Different-Half/m-p/844741#M333963</link>
      <description>&lt;P&gt;I previously only sorted&amp;nbsp; &amp;nbsp;"by monthyear", sorting by&amp;nbsp;"by period monthyear" does the trick.&amp;nbsp;Thank you very much.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 02:19:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Overlay-Series-With-Regression-Trend-Lines-for-Different-Half/m-p/844741#M333963</guid>
      <dc:creator>adejames2000</dc:creator>
      <dc:date>2022-11-17T02:19:00Z</dc:date>
    </item>
  </channel>
</rss>

