<?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 do Regression on Broken/Turning Line?! in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/833839#M329664</link>
    <description>&lt;P&gt;No index, but you can search SAS blogs by using the SITE: keyword in an internet search engine. For example:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;piecewise regression site:blogs.sas.com&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;will locate the two articles that I linked to.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Sep 2022 13:07:55 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2022-09-16T13:07:55Z</dc:date>
    <item>
      <title>How to do Regression on Broken/Turning Line?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/832241#M328931</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let slope1=-2; %let slope2=5; %let turner=30;

data indata;
do i=1 to 100;
	if i&amp;lt;&amp;amp;turner. then y=5*ranuni(i)+i*&amp;amp;slope1.;
	else y=10*ranuni(i)+i*&amp;amp;slope2.-&amp;amp;turner.*&amp;amp;slope2.+&amp;amp;turner.*&amp;amp;slope1.;
	output;
end;
run;quit;

ods listing gpath="%sysfunc(getoption(work))";
proc sgplot data=indata;
scatter x=i y=y; 
run;quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SGPlot5.png" style="width: 336px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75057iE38B0BDAF9C2C4F1/image-size/large?v=v2&amp;amp;px=999" role="button" title="SGPlot5.png" alt="SGPlot5.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I have observations on a broken line alike the one above.&lt;/P&gt;
&lt;P&gt;How to do a fitting to find the parameters (slope1, slope2 and turner)?! Thanks,&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2022 20:06:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/832241#M328931</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2022-09-07T20:06:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to do Regression on Broken/Turning Line?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/832243#M328932</link>
      <description>&lt;P&gt;I mean to fit stepwise line once for all, since turner[the turning point] is uncertain in general.&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2022 20:15:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/832243#M328932</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2022-09-07T20:15:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to do Regression on Broken/Turning Line?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/832253#M328938</link>
      <description>&lt;P&gt;Here's an example with a curved portion and a linear portion; just replace the curved portion with a straight line&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/statug/statug_nlin_examples01.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/statug/statug_nlin_examples01.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Sep 2022 20:57:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/832253#M328938</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-07T20:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to do Regression on Broken/Turning Line?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/832265#M328943</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc nlin data=indata;
   parms slope1=0 slope2=0 x0=50;

   if (x &amp;lt; x0) then
        mean = x*slope1;
   else mean = x*slope2-x0*slope2+x0*slope1;
   model y = mean;

   output out=indata_out predicted=yp;
run;
proc sgplot data=indata_out;
scatter x=x y=y; 
scatter x=x y=yp; 
run;quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Ye, it works. But is set the starting as&lt;CODE class=" language-sas"&gt;&amp;nbsp;slope1=-0.1 slope2=0.1,&amp;nbsp;the&amp;nbsp;outcomes&amp;nbsp;are&amp;nbsp;quite&amp;nbsp;off.&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Sep 2022 01:00:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/832265#M328943</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2022-09-08T01:00:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to do Regression on Broken/Turning Line?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/832283#M328952</link>
      <description>&lt;P&gt;Try other starting values&lt;/P&gt;</description>
      <pubDate>Thu, 08 Sep 2022 10:12:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/832283#M328952</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-08T10:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to do Regression on Broken/Turning Line?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/833785#M329633</link>
      <description>&lt;P&gt;I take the example in the link and it works on my sample dataset. One quest, how to tell whether to take 2-step regression or just 1-step regression.&lt;/P&gt;
&lt;P&gt;When turner is 95 or 98 or 99, somewhere just 1-step (one line) is preferred ... what criteria to take to tell 2-step regression is preferred?!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let slope1=-2; %let slope2=5; %let turner=90;

data indata;
do i=1 to 100;
	if i&amp;lt;&amp;amp;turner. then y=5*ranuni(i)+i*&amp;amp;slope1.;
	else y=10*ranuni(i)+i*&amp;amp;slope2.-&amp;amp;turner.*&amp;amp;slope2.+&amp;amp;turner.*&amp;amp;slope1.;
	output;
end;
run;quit;

ods listing gpath="%sysfunc(getoption(work))";
proc sgplot data=indata;
scatter x=i y=y; 
run;quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Sep 2022 09:25:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/833785#M329633</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2022-09-16T09:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to do Regression on Broken/Turning Line?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/833796#M329640</link>
      <description>&lt;P&gt;This is a question I have never had before, and I admit I don't know if there is a standard answer in this situation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I assume you could compare the fits (via R-squared or RMSE or something similar) of the two models (one model with the break point and one model without). Something like the Extra Sum of Squares F-test makes sense to me. &lt;A href="https://www.sfu.ca/~lockhart/richard/350/08_2/lectures/FTests/web.pdf" target="_blank"&gt;https://www.sfu.ca/~lockhart/richard/350/08_2/lectures/FTests/web.pdf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 10:03:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/833796#M329640</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-16T10:03:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to do Regression on Broken/Turning Line?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/833803#M329643</link>
      <description>&lt;P&gt;My toy sample's plot and Output are below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I bet EST/STDERR on slope1 and slope2[F Test] might be close, since&amp;nbsp;F-Test between 2-step model and 1-step model is not directly available.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BUT I am note sure since not of my expertise.&amp;nbsp;&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="SGPlot31.png" style="width: 640px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75308iDFE055C3921864DF/image-size/large?v=v2&amp;amp;px=999" role="button" title="SGPlot31.png" alt="SGPlot31.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
                                                             The NLIN Procedure

                                                    Estimation Summary (Not Converged)

                                                   Subiterations                      98
                                                   Average Subiterations             3.5
                                                   R                            0.015325
                                                   PPC(intcpt0)                 0.019684
                                                   RPC                                 .
                                                   Object                       3.72E-16
                                                   Objective                     8.39E13
                                                   Observations Read                  66
                                                   Observations Used                  66
                                                   Observations Missing                0


                                                                   Sum of        Mean               Approx
                                 Source                    DF     Squares      Square    F Value    Pr &amp;gt; F

                                 Model                      3    1.124E15    3.746E14     276.85    &amp;lt;.0001
                                 Error                     62     8.39E13    1.353E12
                                 Corrected Total           65    1.208E15


                                                                      Approx
                                        Parameter      Estimate    Std Error    Approximate 95% Confidence Limits

                                        intcpt0         1453782       526391      401542     2506022
                                        slope1          -482416      41921.6     -566216     -398615
                                        slope2          -121843      13352.5     -148534    -95151.8
                                        x0              21.0000       1.6745     17.6526     24.3474


                                                      Approximate Correlation Matrix
                                                  intcpt0          slope1          slope2              x0

                                  intcpt0       1.0000000      -0.8760376      -0.0000000      -0.4054904
                                  slope1       -0.8760376       1.0000000       0.0000000       0.6943031
                                  slope2       -0.0000000       0.0000000       1.0000000       0.5086293
                                  x0           -0.4054904       0.6943031       0.5086293       1.0000000


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Sep 2022 10:23:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/833803#M329643</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2022-09-16T10:23:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to do Regression on Broken/Turning Line?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/833804#M329644</link>
      <description>&lt;P&gt;You would have to code the equivalent of something like extra-sum-of-squares F-test yourself, based upon your PROC NLIN output. (Or do it with a calculator)&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 10:31:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/833804#M329644</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-16T10:31:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to do Regression on Broken/Turning Line?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/833828#M329656</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt; wrote a blog about this topic before.</description>
      <pubDate>Fri, 16 Sep 2022 12:23:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/833828#M329656</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-09-16T12:23:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to do Regression on Broken/Turning Line?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/833831#M329659</link>
      <description>&lt;P&gt;This is called a piecewise linear model when each regression curve is linear. In general, these are called segmented models. See&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://blogs.sas.com/content/iml/2017/04/05/nonsmooth-models-spline-effects.html" target="_self"&gt;Piecewise regression models and spline effects&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://blogs.sas.com/content/iml/2020/12/14/segmented-regression-sas.html" target="_self"&gt;Segmented regression models in SAS&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Fri, 16 Sep 2022 12:43:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/833831#M329659</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-09-16T12:43:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to do Regression on Broken/Turning Line?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/833833#M329661</link>
      <description>&lt;P&gt;Is there an index/list of topics that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;has written about? Or should we just assume that he has written about every possible topic &lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt;&lt;span class="lia-unicode-emoji" title=":weary_cat_face:"&gt;🙀&lt;/span&gt;&lt;span class="lia-unicode-emoji" title=":thumbs_up:"&gt;👍&lt;/span&gt; ?&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 12:48:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/833833#M329661</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-16T12:48:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to do Regression on Broken/Turning Line?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/833839#M329664</link>
      <description>&lt;P&gt;No index, but you can search SAS blogs by using the SITE: keyword in an internet search engine. For example:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;piecewise regression site:blogs.sas.com&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;will locate the two articles that I linked to.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 13:07:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/833839#M329664</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-09-16T13:07:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to do Regression on Broken/Turning Line?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/833844#M329666</link>
      <description>&lt;P&gt;Thanks! Actually, Google is almost as good as an index/list.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 13:19:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/833844#M329666</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-09-16T13:19:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to do Regression on Broken/Turning Line?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/833923#M329698</link>
      <description>&lt;P&gt;The example given at R seems show that EST/STDERR for each slope is not a good tell (slope1 abs-t-value &amp;lt;1.0).&lt;/P&gt;
&lt;P&gt;The visual tells a segmented line there.&lt;/P&gt;
&lt;P&gt;My quest is how to tell whether 2-step/segment is better than 1-step (or 3-step is better than 2-step).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;gt; slope(o)
$x
            Est.  St.Err.  t value CI(95%).l  CI(95%).u
slope1 -0.058993 0.062105 -0.94991  -0.18230 0.06431700
slope2  1.414600 0.046151 30.65100   1.32290 1.50620000
slope3 -0.142800 0.071994 -1.98350  -0.28575 0.00014734&lt;/CODE&gt;&lt;/PRE&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="R_OUT.jpg" style="width: 673px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/75332i449D564482D11C56/image-size/large?v=v2&amp;amp;px=999" role="button" title="R_OUT.jpg" alt="R_OUT.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;# http://127.0.0.1:16212/library/segmented/html/segmented.html

set.seed(12)
xx&amp;lt;-1:100
zz&amp;lt;-runif(100)
yy&amp;lt;-2+1.5*pmax(xx-35,0)-1.5*pmax(xx-70,0)+15*pmax(zz-.5,0)+rnorm(100,0,2)
dati&amp;lt;-data.frame(x=xx,y=yy,z=zz)
out.lm&amp;lt;-lm(y~x,data=dati)

#the simplest example: the starting model includes just 1 covariate 
#.. and 1 breakpoint has to be estimated for that
o&amp;lt;-segmented(out.lm) #1 breakpoint for x

#the single segmented variable is not in the starting model and 1 breakpoint for that:
#... you need to specify the variable via seg.Z, but no starting value for psi
o&amp;lt;-segmented(out.lm, seg.Z=~z)
#note the leftmost slope is constrained to be zero (since out.lm does not include z)

#2 segmented variables, 1 breakpoint each (again no need to specify npsi or psi)
o&amp;lt;-segmented(out.lm,seg.Z=~z+x)


#1 segmented variable, 2 breakpoints: you have to specify starting values (vector) for psi:
o&amp;lt;-segmented(out.lm,seg.Z=~x,psi=c(30,60), control=seg.control(display=FALSE))

#or by specifying just the *number* of breakpoints
#o&amp;lt;-segmented(out.lm,seg.Z=~x, npsi=2, control=seg.control(display=FALSE)) 

slope(o) #the slopes of the segmented relationship

dat2 = data.frame(x = xx, y = broken.line(o)$fit)

ggplot(dati, aes(x = x, y = y)) +
  geom_point() +
  geom_line(data = dat2, color = 'blue')&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Sep 2022 22:22:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/833923#M329698</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2022-09-16T22:22:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to do Regression on Broken/Turning Line?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/833928#M329701</link>
      <description>&lt;P&gt;Well, EST/STDERR tells slopex=0.0 or not. But still any criteria to tell whether take n-segment rather than (n-1) segment?!&lt;/P&gt;</description>
      <pubDate>Fri, 16 Sep 2022 22:32:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/833928#M329701</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2022-09-16T22:32:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to do Regression on Broken/Turning Line?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/833938#M329703</link>
      <description>&lt;P&gt;I set turner=95, and fetch ESS and follow "Hypothesis Test, 3.2" and get&lt;/P&gt;
&lt;P&gt;ESS_F=((315653-318355)/2)/(318355/96)=-0.4, somewhere must be not right ??!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%let slope1=-2; %let slope2=5; %let turner=95;

data indata;
do ind=1 to 100;
	if ind&amp;lt;&amp;amp;turner. then y=10*ranuni(ind)+ind*&amp;amp;slope1.;
	else y=20*ranuni(ind)+ind*&amp;amp;slope2.-&amp;amp;turner.*&amp;amp;slope2.+&amp;amp;turner.*&amp;amp;slope1.;
	output;
end;
run;quit;

ods listing gpath="%sysfunc(getoption(work))";
proc sgplot data=indata;
scatter x=ind y=y; 
run;quit;

%let inds=indata;
%let xvar=ind; %let yvar=y;

	proc nlin data=&amp;amp;inds.;
	   parms intcpt0=0 slope1=0 slope2=0 x0=&amp;amp;st_x0;
	   if (ind &amp;lt; x0) then
	        mean = intcpt0+ind*slope1;
	   else mean = ind*slope2-x0*slope2+x0*slope1+intcpt0;
	   model &amp;amp;yvar. = mean;

	   output out=&amp;amp;inds._sel_out predicted=&amp;amp;yvar._p;
	run;

	proc reg data=&amp;amp;inds.;
	model y=ind;run;quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
                                                             The REG Procedure
                                                               Model: MODEL1
                                                           Dependent Variable: y

                                                  Number of Observations Read         100
                                                  Number of Observations Used         100


                                                            Analysis of Variance

                                                                   Sum of           Mean
                               Source                   DF        Squares         Square    F Value    Pr &amp;gt; F

                               Model                     1         315653         315653    8832.21    &amp;lt;.0001
                               Error                    98     3502.40844       35.73886
                               Corrected Total          99         319156


                                            Root MSE              5.97820    R-Square     0.9890
                                            Dependent Mean      -94.98238    Adj R-Sq     0.9889
                                            Coeff Var            -6.29401


                                                            Parameter Estimates

                                                         Parameter       Standard
                                    Variable     DF       Estimate          Error    t Value    Pr &amp;gt; |t|

                                    Intercept     1        3.30749        1.20466       2.75      0.0072
                                    ind           1       -1.94633        0.02071     -93.98      &amp;lt;.0001


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
                                                             The NLIN Procedure

                                                                   Sum of        Mean               Approx
                                 Source                    DF     Squares      Square    F Value    Pr &amp;gt; F

                                 Model                      3      318355      106118    12731.3    &amp;lt;.0001
                                 Error                     96       800.2      8.3353
                                 Corrected Total           99      319156


                                                                      Approx
                                        Parameter      Estimate    Std Error    Approximate 95% Confidence Limits

                                        intcpt0          5.6447       0.6003      4.4530      6.8363
                                        slope1          -2.0169       0.0110     -2.0387     -1.9951
                                        slope2           4.5742       0.6901      3.2043      5.9441
                                        x0              94.3985       0.3816     93.6411     95.1559


                                                      Approximate Correlation Matrix
                                                  intcpt0          slope1          slope2              x0

                                  intcpt0       1.0000000      -0.8683135      -0.0000000      -0.1189745
                                  slope1       -0.8683135       1.0000000       0.0000000       0.2046574
                                  slope2       -0.0000000       0.0000000       1.0000000       0.8511409
                                  x0           -0.1189745       0.2046574       0.8511409       1.0000000
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Sep 2022 01:11:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/833938#M329703</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2022-09-17T01:11:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to do Regression on Broken/Turning Line?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/833959#M329712</link>
      <description>&lt;P&gt;The usual way to compare two different regression models is to compare some criteria such as the AIC, BIC, or SBC. These criteria are not produced automatically by PROC NLIN, but you can use PROC NLMIXED (which has a similar syntax) to get them. Look at the "Fit Statistics" table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 17 Sep 2022 10:13:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/833959#M329712</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-09-17T10:13:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to do Regression on Broken/Turning Line?!</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/834007#M329729</link>
      <description>&lt;P&gt;Would you give out an example with dataset or a link?! Dear Paige gives out a great link on hypo test between&amp;nbsp;&lt;/P&gt;
&lt;P&gt;models,&amp;nbsp;&lt;A href="https://www.sfu.ca/~lockhart/richard/350/08_2/lectures/FTests/web.pdf" target="_blank"&gt;https://www.sfu.ca/~lockhart/richard/350/08_2/lectures/FTests/web.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Somehow, when I run my toy dataset, the F-test shows up confusing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let slope1=-2; %let slope2=5; %let turner=95;

data indata;
do ind=1 to 100;
	if ind&amp;lt;&amp;amp;turner. then y=10*ranuni(ind)+ind*&amp;amp;slope1.;
	else y=20*ranuni(ind)+ind*&amp;amp;slope2.-&amp;amp;turner.*&amp;amp;slope2.+&amp;amp;turner.*&amp;amp;slope1.;
	output;
end;
run;quit;

ods listing gpath="%sysfunc(getoption(work))";
proc sgplot data=indata;
scatter x=ind y=y; 
run;quit;

%let inds=indata;
%let xvar=ind; %let yvar=y;

	proc nlin data=&amp;amp;inds.;
	   parms intcpt0=0 slope1=0 slope2=0 x0=&amp;amp;st_x0;
	   if (ind &amp;lt; x0) then
	        mean = intcpt0+ind*slope1;
	   else mean = ind*slope2-x0*slope2+x0*slope1+intcpt0;
	   model &amp;amp;yvar. = mean;

	   output out=&amp;amp;inds._sel_out predicted=&amp;amp;yvar._p;
	run;

	proc reg data=&amp;amp;inds.;
	model y=ind;run;quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 18 Sep 2022 00:58:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-Regression-on-Broken-Turning-Line/m-p/834007#M329729</guid>
      <dc:creator>hellohere</dc:creator>
      <dc:date>2022-09-18T00:58:42Z</dc:date>
    </item>
  </channel>
</rss>

