<?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: Identify Zigzag point for timeseries in SAS Forecasting and Econometrics</title>
    <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/844987#M4548</link>
    <description>&lt;P&gt;I added a picture link in my original post.&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
    <pubDate>Thu, 17 Nov 2022 21:41:16 GMT</pubDate>
    <dc:creator>hhchenfx</dc:creator>
    <dc:date>2022-11-17T21:41:16Z</dc:date>
    <item>
      <title>Identify Zigzag point for timeseries</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/844982#M4546</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;I want to find the zigzag point for timeseries and quite surprise, there isn't much discussion on this topic.&lt;/P&gt;
&lt;P&gt;In the data below, the zigzag point should be number 10, 1 and 10&lt;/P&gt;
&lt;P&gt;Can you please help me with the code?&lt;/P&gt;
&lt;P&gt;The zigzag line is in picture below&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.google.com/imgres?imgurl=https%3A%2F%2Fi.stack.imgur.com%2FjphC7.png&amp;amp;imgrefurl=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F59559788%2Fpandas-zigzag-segmentation-of-data-based-on-local-minima-maxima&amp;amp;tbnid=t3U3wqE3BewlbM&amp;amp;vet=12ahUKEwi9mfXGlrb7AhV2mHIEHTumBacQMygLegUIARDKAQ..i&amp;amp;docid=Al5NbnEIPnABSM&amp;amp;w=1769&amp;amp;h=871&amp;amp;q=zigzag%20timeseries&amp;amp;ved=2ahUKEwi9mfXGlrb7AhV2mHIEHTumBacQMygLegUIARDKAQ" target="_blank"&gt;https://www.google.com/imgres?imgurl=https%3A%2F%2Fi.stack.imgur.com%2FjphC7.png&amp;amp;imgrefurl=https%3A%2F%2Fstackoverflow.com%2Fquestions%2F59559788%2Fpandas-zigzag-segmentation-of-data-based-on-local-minima-maxima&amp;amp;tbnid=t3U3wqE3BewlbM&amp;amp;vet=12ahUKEwi9mfXGlrb7AhV2mHIEHTumBacQMygLegUIARDKAQ..i&amp;amp;docid=Al5NbnEIPnABSM&amp;amp;w=1769&amp;amp;h=871&amp;amp;q=zigzag%20timeseries&amp;amp;ved=2ahUKEwi9mfXGlrb7AhV2mHIEHTumBacQMygLegUIARDKAQ&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input value;
datalines;
6
7
8
8
10
9
8
8
8
7
6
8
8
4
5
1
2
3
4
6
6
8
9
10
6
8
6
5
1
;run;

data have; set have;
n=_N_;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 21:40:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/844982#M4546</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-11-17T21:40:42Z</dc:date>
    </item>
    <item>
      <title>Re: Identify Zigzag point for timeseries</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/844986#M4547</link>
      <description>&lt;P&gt;I have never heard of a Zigzag point. What is the logic? And what does your desired result look like here?&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 21:29:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/844986#M4547</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-17T21:29:23Z</dc:date>
    </item>
    <item>
      <title>Re: Identify Zigzag point for timeseries</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/844987#M4548</link>
      <description>&lt;P&gt;I added a picture link in my original post.&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 21:41:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/844987#M4548</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-11-17T21:41:16Z</dc:date>
    </item>
    <item>
      <title>Re: Identify Zigzag point for timeseries</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/844988#M4549</link>
      <description>&lt;P&gt;It does not explain the logic. Please be more specific about your requirements.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Nov 2022 21:42:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/844988#M4549</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-11-17T21:42:44Z</dc:date>
    </item>
    <item>
      <title>Re: Identify Zigzag point for timeseries</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/845019#M4550</link>
      <description>&lt;P&gt;You want to effectively finds local minima and maxima in a time series.&amp;nbsp; Those local extremes can then be connected to generate a set of zigzag line segments.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you have to define for us&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;what "local" is, i.e. how large a window is required to examine for a change in direction, and&lt;/LI&gt;
&lt;LI&gt;how large a change in direction must be to designate the local minimum or maximum.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Fri, 18 Nov 2022 19:21:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/845019#M4550</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-11-18T19:21:21Z</dc:date>
    </item>
    <item>
      <title>Re: Identify Zigzag point for timeseries</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/845031#M4551</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;,&amp;nbsp;you are 100% correct. The thing is for that Zigzag, normally other software have the "local" and "size of change" parameters and user can adjust.&lt;/P&gt;
&lt;P&gt;Can you do something like that?&lt;/P&gt;
&lt;P&gt;I find it quite weird that I can't find any code for this very popular timeseries measure &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 03:32:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/845031#M4551</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-11-18T03:32:45Z</dc:date>
    </item>
    <item>
      <title>Re: Identify Zigzag point for timeseries</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/845087#M4552</link>
      <description>&lt;P&gt;calling &amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Here could give you a start*/
data have;
input value;
n+1;
datalines;
6
7
8
8
10
9
8
8
8
7
6
8
8
4
5
1
2
3
4
6
6
8
9
10
6
8
6
5
1
;

proc iml;
use have;
read all var _num_ into Pts[c=vname];
close;
 indices = cvexhull(Pts);            /* compute convex hull of the N points */
 hullIdx = indices[loc(indices&amp;gt;0)];  
 P = Pts[hullIdx, ];  
 call sort(p,2);
create p from p[c=vname];
append from p;
close;
quit;
data p2;
 set p;
 sign=sign(dif(value));
run;
data p3;
 set p2;
 by sign notsorted;
 if last.sign;
run;
data want;
 set have p3(rename=(n=_n value=_v));
run;

proc sgplot data=want;
series x=n y=value;
scatter x=_n y=_v/markerattrs=(symbol=starfilled color=red);
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-1668772318644.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77438i6BD15C213C1D78D0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1668772318644.png" alt="Ksharp_0-1668772318644.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 11:51:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/845087#M4552</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-11-18T11:51:28Z</dc:date>
    </item>
    <item>
      <title>Re: Identify Zigzag point for timeseries</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/845107#M4553</link>
      <description>&lt;P&gt;I haven't heard the term "zigzag point" before, but it seems that you want to identify peaks and valleys in a noisy signal by using certain criteria about the height of the peaks and the width between peaks. In SAS Viya, you can use &lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/v_033/casimllang/casimllang_common_sect282.htm" target="_self"&gt;the PEAKLOC and PEAKINFO functions&lt;/A&gt; in SAS IML to identify peaks in a signal. These functions are not available in SAS 9.4.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://go.documentation.sas.com/doc/en/espcdc/v_028/espan/n1a24zmowg07opn1ul03ulh6g23c.htm#n1uhx5q8cy0ypwn1w0cbr0z094qw" target="_self"&gt;SAS Event-Stream Processing also supports various methods for locating peaks.&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since this question appears related to time series, I will move it to a more appropriate community where experts like&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/43004"&gt;@rselukar&lt;/a&gt;&amp;nbsp;might see it and provide additional assistance.&lt;/P&gt;</description>
      <pubDate>Fri, 18 Nov 2022 13:58:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/845107#M4553</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-11-18T13:58:44Z</dc:date>
    </item>
    <item>
      <title>Re: Identify Zigzag point for timeseries</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/845238#M4554</link>
      <description>&lt;P&gt;Thank you, Ksharp.&lt;/P&gt;
&lt;P&gt;I am digesting your code &lt;span class="lia-unicode-emoji" title=":grinning_squinting_face:"&gt;😆&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
      <pubDate>Sat, 19 Nov 2022 01:22:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/845238#M4554</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-11-19T01:22:21Z</dc:date>
    </item>
    <item>
      <title>Re: Identify Zigzag point for timeseries</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/845254#M4555</link>
      <description>"In SAS Viya, you can use the PEAKLOC and PEAKINFO functions in SAS IML to identify peaks in a signal. These functions are not available in SAS 9.4. "&lt;BR /&gt;&lt;BR /&gt;Disappointed . Need pay money for it .</description>
      <pubDate>Sat, 19 Nov 2022 08:38:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/845254#M4555</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-11-19T08:38:33Z</dc:date>
    </item>
    <item>
      <title>Re: Identify Zigzag point for timeseries</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/845296#M4556</link>
      <description>&lt;P&gt;I might have to think about a way to include parameter to the code so I can provide more flexibility.&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
      <pubDate>Sun, 20 Nov 2022 00:00:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/845296#M4556</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-11-20T00:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: Identify Zigzag point for timeseries</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/845317#M4557</link>
      <description>&lt;P&gt;You can split this time series into many small series ,and use my code to get these points you want.&lt;/P&gt;
&lt;P&gt;Or calling&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp;,please let him wrote a IML code for you ?&lt;/P&gt;</description>
      <pubDate>Sun, 20 Nov 2022 08:23:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/845317#M4557</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-11-20T08:23:17Z</dc:date>
    </item>
    <item>
      <title>Re: Identify Zigzag point for timeseries</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/845331#M4558</link>
      <description>&lt;P&gt;LOL. I have a full-time job already, but thanks for thinking of me. Let's hear what the time series experts say.&lt;/P&gt;</description>
      <pubDate>Sun, 20 Nov 2022 11:48:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/845331#M4558</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2022-11-20T11:48:58Z</dc:date>
    </item>
    <item>
      <title>Re: Identify Zigzag point for timeseries</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/845543#M4559</link>
      <description>&lt;P&gt;The responses given so far are quite good.&amp;nbsp;I am not aware of any thing in SAS/ETS or (SAS/ECONOMETRICS) that is specifically designed for peak-discovery.&amp;nbsp; I think this problem can also be called identifying turning points of a time series.&amp;nbsp; For noisy time series the interest could be in finding the turning points of the underlying smooth signal.&amp;nbsp; I will describe a quick way of doing this by using PROC UCM in SAS/ETS.&amp;nbsp; Of course, this is a solution to a related problem and not the original one.&lt;/P&gt;
&lt;P&gt;Let's say the value_t series can be thought of as a sum of&amp;nbsp; mu_t, a smooth curve, and noise_t: value_t = mu_t + noise_t.&amp;nbsp; The following code shows you how to fit this model when mu_t is modeled by an integrated random walk, which produces cubic smoothing spline, and Gaussian white noise:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;proc ucm data=have;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; id n interval=obs;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; model value;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; irregular;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; level variance=0 noest;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; slope plot=smooth;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; forecast lead=0 outfor=for plot=decomp;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;The output data set "for" contains the estimates of mu_t and its slope (the columns s_level and s_slope).&amp;nbsp; The turning points of mu_t could be located as places where the sign of adjacent s_level values change (i.e., points where s_level stops going upward/downward).&amp;nbsp; These points are located by the following data steps:&lt;/P&gt;
&lt;P&gt;data change;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; set for(keep=n value s_level s_slope);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; s1 = lag(s_slope);&lt;BR /&gt;&amp;nbsp; &amp;nbsp; turn = 0;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if n &amp;gt;= 2 then do;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if sign(s1) ^= sign(s_slope) then turn=1;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;*The turns data set contains the discovered turn points: 5 17 24;&lt;/P&gt;
&lt;P&gt;data turns;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; set change;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; where turn=1;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;The following plot shows how well s_level approximates the original series:&lt;/P&gt;
&lt;DIV id="tinyMceEditorrselukar_0" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="rselukar_3-1669059034473.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77517iB78BCBFEAA4D16F2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="rselukar_3-1669059034473.png" alt="rselukar_3-1669059034473.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="tinyMceEditorrselukar_1" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;The following curve plots the slope (s_slope):&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="rselukar_4-1669059136916.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77518i5B1EF762CCDE7623/image-size/medium?v=v2&amp;amp;px=400" role="button" title="rselukar_4-1669059136916.png" alt="rselukar_4-1669059136916.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV id="tinyMceEditorrselukar_2" class="mceNonEditable lia-copypaste-placeholder"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;The following code shows the discovered turning points:&lt;/P&gt;
&lt;P&gt;proc sgplot data=change;&lt;BR /&gt;title Plot of smoothed_value with identified turning points;&lt;BR /&gt;series x=n y=s_level;&lt;BR /&gt;refline 5 17 24/ axis=x;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="rselukar_5-1669059275490.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77519i52BF2E76CA51706E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="rselukar_5-1669059275490.png" alt="rselukar_5-1669059275490.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course, the identified turning points are not the turning points of the original series but of the underlying smooth signal.&amp;nbsp; The following plot shows how they appear for the original curve:&lt;/P&gt;
&lt;P&gt;proc sgplot data=change;&lt;BR /&gt;title Plot of value with identified turning points for smoothed_value;&lt;BR /&gt;series x=n y=value;&lt;BR /&gt;refline 5 17 24/ axis=x;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="rselukar_6-1669059447322.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77521i5AEE1E1F13BF15E2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="rselukar_6-1669059447322.png" alt="rselukar_6-1669059447322.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know this is a bit lengthy response.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Nov 2022 19:40:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/845543#M4559</guid>
      <dc:creator>rselukar</dc:creator>
      <dc:date>2022-11-21T19:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: Identify Zigzag point for timeseries</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/845601#M4560</link>
      <description>&lt;P&gt;I tested&amp;nbsp;rselukar 's code and got this :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 set sashelp.stocks;
 if stock='Intel';
 keep date stock close;
run;
proc sort data=have;by date;run;
data have2;
 set have(keep=close rename=(close=value));
 n+1;
run;

proc ucm data=have2;
    id n interval=obs;
    model value;
    irregular;
    level variance=0 noest;
    slope plot=smooth;
    forecast lead=0 outfor=for plot=decomp;
run;



data change;
    set for(keep=n value s_level s_slope);
    s1 = lag(s_slope);
    turn = 0;
    if n &amp;gt;= 2 then do;
        if sign(s1) ^= sign(s_slope) then turn=1;
    end;
run;
data turns;
    set change;
    where turn=1;
run;
data all;
 set have2 turns(keep=n value rename=(n=_n value=_v));
run;
proc sgplot data=all;
title Plot of smoothed_value with identified turning points;
series x=n y=value;
scatter x=_n y=_v/markerattrs=(symbol=starfilled color=red);
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-1669091791739.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77534iD6EF48A098CA77A3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1669091791739.png" alt="Ksharp_0-1669091791739.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 04:36:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/845601#M4560</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-11-22T04:36:03Z</dc:date>
    </item>
    <item>
      <title>Re: Identify Zigzag point for timeseries</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/845696#M4561</link>
      <description>&lt;P&gt;By the way, as I mentioned earlier, the turning points are for the underlying smooth signal (s_level).&amp;nbsp; &amp;nbsp;You can slightly alter&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/336386"&gt;@jacksharp&lt;/a&gt;'s code to get the plot of turning points of s_level as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data all;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; set change turns(keep=n s_level rename=(n=_n s_level=_v));&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;proc sgplot data=all;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;title Plot of smoothed_value with identified turning points;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;series x=n y=s_level;&lt;BR /&gt;&amp;nbsp; &amp;nbsp;scatter x=_n y=_v/markerattrs=(symbol=starfilled color=red);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;Which results in the following plot:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="rselukar_0-1669131640845.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77554iC9642F1F7902B728/image-size/medium?v=v2&amp;amp;px=400" role="button" title="rselukar_0-1669131640845.png" alt="rselukar_0-1669131640845.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Of course,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/336386"&gt;@jacksharp&lt;/a&gt;'s way of showing the turning points is much better than my earlier plots.&amp;nbsp; Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 15:45:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/845696#M4561</guid>
      <dc:creator>rselukar</dc:creator>
      <dc:date>2022-11-22T15:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: Identify Zigzag point for timeseries</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/845783#M4563</link>
      <description>&lt;P&gt;Thank you all for helping.&lt;/P&gt;
&lt;P&gt;It is great code.&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2022 21:46:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Identify-Zigzag-point-for-timeseries/m-p/845783#M4563</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2022-11-22T21:46:29Z</dc:date>
    </item>
  </channel>
</rss>

