<?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 calculate std on an increasing data, similar to commulative sum in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-std-on-an-increasing-data-similar-to/m-p/944860#M370196</link>
    <description>&lt;P&gt;All 3 replies to my question are good solutions&lt;/P&gt;
&lt;P&gt;Thanks so much &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 23 Sep 2024 04:37:07 GMT</pubDate>
    <dc:creator>J111</dc:creator>
    <dc:date>2024-09-23T04:37:07Z</dc:date>
    <item>
      <title>how to calculate std on an increasing data, similar to commulative sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-std-on-an-increasing-data-similar-to/m-p/944842#M370188</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;How can we calculate std on data that has an additional row each time.&lt;/P&gt;
&lt;P&gt;It is not a regular moving std , as the data window size increases each time.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data available ;&lt;BR /&gt;input dt y ;&lt;BR /&gt;cards ;&lt;BR /&gt;1 80&lt;BR /&gt;2 20&lt;BR /&gt;3 40&lt;BR /&gt;4 60&lt;BR /&gt;;&lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;data wanted ;&lt;BR /&gt;input dt std ;&lt;BR /&gt;cards ;&lt;BR /&gt;1 80 .&lt;BR /&gt;2 20 42.426406871&lt;BR /&gt;3 40 30.550504633&lt;BR /&gt;4 60 25.819888975 &lt;BR /&gt;;&lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;data calc ;&lt;BR /&gt;x1 = 80 ; &lt;BR /&gt;x2 = 20 ;&lt;BR /&gt;x3 = 40 ;&lt;BR /&gt;x4 = 60 ;&lt;BR /&gt;new1 = std(x1,x2) ; *42.426406871 ;&lt;BR /&gt;new2 = std(x1,x2,x3) ; *30.550504633 ;&lt;BR /&gt;new3 = std(x1,x2,x3,x4) ;* 25.819888975 ;&lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sun, 22 Sep 2024 12:37:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-std-on-an-increasing-data-similar-to/m-p/944842#M370188</guid>
      <dc:creator>J111</dc:creator>
      <dc:date>2024-09-22T12:37:13Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate std on an increasing data, similar to commulative sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-std-on-an-increasing-data-similar-to/m-p/944843#M370189</link>
      <description>&lt;P&gt;oops..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data available ;&lt;BR /&gt;input dt y ;&lt;BR /&gt;cards ;&lt;BR /&gt;1 80&lt;BR /&gt;2 20&lt;BR /&gt;3 40&lt;BR /&gt;4 60&lt;BR /&gt;;&lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;data wanted ;&lt;BR /&gt;input dt y std ;* &amp;lt;---&lt;STRONG&gt;three input variables&lt;/STRONG&gt; ;&lt;BR /&gt;cards ;&lt;BR /&gt;1 80 .&lt;BR /&gt;2 20 42.426406871&lt;BR /&gt;3 40 30.550504633&lt;BR /&gt;4 60 25.819888975&lt;BR /&gt;;&lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;data calc ;&lt;BR /&gt;x1 = 80 ;&lt;BR /&gt;x2 = 20 ;&lt;BR /&gt;x3 = 40 ;&lt;BR /&gt;x4 = 60 ;&lt;BR /&gt;new1 = std(x1,x2) ; *42.426406871 ;&lt;BR /&gt;new2 = std(x1,x2,x3) ; *30.550504633 ;&lt;BR /&gt;new3 = std(x1,x2,x3,x4) ;* 25.819888975 ;&lt;BR /&gt;run ;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Sep 2024 12:47:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-std-on-an-increasing-data-similar-to/m-p/944843#M370189</guid>
      <dc:creator>J111</dc:creator>
      <dc:date>2024-09-22T12:47:08Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate std on an increasing data, similar to commulative sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-std-on-an-increasing-data-similar-to/m-p/944845#M370190</link>
      <description>&lt;P&gt;Thanks for providing data as a SAS data step. Very helpful. I wish more people would do that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This seems to work. If you have thousands or millions of observations, this will note scale up efficiently.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data available ;
input dt y ;
cards ;
1 80
2 20
3 40
4 60
;

/* Compute number of observations in data set available */
/* Code from https://communities.sas.com/t5/SAS-Communities-Library/Determining-the-number-of-observations-in-a-SAS-data-set/ta-p/475174 */
data _NULL_;
	if 0 then set available nobs=n;
	call symputx('nrows',n);
	stop;
run;


data intermediate;
    set available;
    do group=_n_ to &amp;amp;nrows;
        thisy=y;
        output;
    end;
run;
        
proc summary data=intermediate nway;
    class group;
    var thisy;
    output out=want stddev=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 22 Sep 2024 14:48:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-std-on-an-increasing-data-similar-to/m-p/944845#M370190</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-09-22T14:48:00Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate std on an increasing data, similar to commulative sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-std-on-an-increasing-data-similar-to/m-p/944852#M370191</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/386728"&gt;@J111&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also compute the cumulative standard deviation using Steiner's theorem:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=_:);
set available;
retain _v 0;
_s+y; /* cumulative sum */
_m=_s/_n_; /* cumulative mean */
_d=dif(_m); /* mean change */
_q=(y-_m)**2; /* new term in sum of squares */
if _n_&amp;gt;1 then do;
  std=sqrt(_v+_d**2+_q/(_n_-1)); /* cumulative standard deviation */
  _v=((_n_-1)*(_v+_d**2)+_q)/_n_; /* cumulative population variance */
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This calculation should take less than one second for a million observations.&lt;/P&gt;</description>
      <pubDate>Sun, 22 Sep 2024 17:05:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-std-on-an-increasing-data-similar-to/m-p/944852#M370191</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-09-22T17:05:56Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate std on an increasing data, similar to commulative sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-std-on-an-increasing-data-similar-to/m-p/944858#M370194</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data available ;
input dt y ;
cards ;
1 80
2 20
3 40
4 60
;
data want;
 set available;
 array x{999999} _temporary_;
 x{_n_}=y;
 std=std(of x{*});
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Sep 2024 01:20:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-std-on-an-increasing-data-similar-to/m-p/944858#M370194</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-09-23T01:20:55Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate std on an increasing data, similar to commulative sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-std-on-an-increasing-data-similar-to/m-p/944860#M370196</link>
      <description>&lt;P&gt;All 3 replies to my question are good solutions&lt;/P&gt;
&lt;P&gt;Thanks so much &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2024 04:37:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-std-on-an-increasing-data-similar-to/m-p/944860#M370196</guid>
      <dc:creator>J111</dc:creator>
      <dc:date>2024-09-23T04:37:07Z</dc:date>
    </item>
    <item>
      <title>Re: how to calculate std on an increasing data, similar to commulative sum</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-std-on-an-increasing-data-similar-to/m-p/944863#M370198</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next, if we wanted to add another field such as group by and&lt;/P&gt;
&lt;P&gt;calculate the std for each value of gr in the data below:-&lt;/P&gt;
&lt;P&gt;what would be the best solution ? Thanks&amp;nbsp; a lot.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data available ;&lt;BR /&gt;input gr dt y ;&lt;BR /&gt;cards ;&lt;BR /&gt;1 1 80&lt;BR /&gt;1 2 20&lt;BR /&gt;1 3 40&lt;BR /&gt;1 4 60&lt;BR /&gt;2 1 80&lt;BR /&gt;2 2 20&lt;BR /&gt;2 3 40&lt;BR /&gt;2 4 50&lt;BR /&gt;;&lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;data wanted ;&lt;BR /&gt;input gr dt y std ;&lt;BR /&gt;cards ;&lt;BR /&gt;1 1 80&lt;BR /&gt;1 2 20 42.426406871&lt;BR /&gt;1 3 40 30.550504633&lt;BR /&gt;1 4 60 25.819888975&lt;BR /&gt;2 1 80&lt;BR /&gt;2 2 20 42.426406871&lt;BR /&gt;2 3 40 30.550504633&lt;BR /&gt;2 4 50 25&lt;BR /&gt;;&lt;BR /&gt;run ;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Sep 2024 05:52:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-calculate-std-on-an-increasing-data-similar-to/m-p/944863#M370198</guid>
      <dc:creator>J111</dc:creator>
      <dc:date>2024-09-23T05:52:12Z</dc:date>
    </item>
  </channel>
</rss>

