<?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 teh  rolling standard deviations? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-teh-rolling-standard-deviations/m-p/98388#M27686</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Patrick,&lt;/P&gt;&lt;P&gt;Thanks. I think it is good enough for me.&lt;/P&gt;&lt;P&gt;Anna&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 05 Apr 2013 02:51:45 GMT</pubDate>
    <dc:creator>Anna_Guo</dc:creator>
    <dc:date>2013-04-05T02:51:45Z</dc:date>
    <item>
      <title>How to calculate teh  rolling standard deviations?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-teh-rolling-standard-deviations/m-p/98383#M27681</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have 30 years of profit data, and I want to calculate standard deviation for each year using past 5 years profits. The first year with standard deviation data should be the 6th year. ( I calculate the standard deviation for year 6 to year 30 ).&lt;/P&gt;&lt;P&gt;Please help.&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Apr 2013 01:03:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-teh-rolling-standard-deviations/m-p/98383#M27681</guid>
      <dc:creator>Anna_Guo</dc:creator>
      <dc:date>2013-04-05T01:03:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate teh  rolling standard deviations?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-teh-rolling-standard-deviations/m-p/98384#M27682</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since you don't have sample data, I can only give out general suggestions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Use Proc Expand. It has moving standard deviation built-in. it is the easiest way, but it requires license of SAS/ETS.&lt;/P&gt;&lt;P&gt;2. Use Lagn(), in your case, Lag5().&lt;/P&gt;&lt;P&gt;3. Use temporary Array(), presumably the most efficient one?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Upon seeing your sample data, all of these approaches could be finalized. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Apr 2013 02:04:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-teh-rolling-standard-deviations/m-p/98384#M27682</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-04-05T02:04:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate teh  rolling standard deviations?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-teh-rolling-standard-deviations/m-p/98385#M27683</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hai.Guo&lt;/P&gt;&lt;P&gt;I attached the simplified data,&amp;nbsp; One more thing, I need to do this by gvkey ( company id). I have thousands companies. Please help me with the code. I am not good at array function.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Anna&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Apr 2013 02:19:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-teh-rolling-standard-deviations/m-p/98385#M27683</guid>
      <dc:creator>Anna_Guo</dc:creator>
      <dc:date>2013-04-05T02:19:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate teh  rolling standard deviations?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-teh-rolling-standard-deviations/m-p/98386#M27684</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Below code works under the assumption that you don't have missing years.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;&amp;nbsp; array arr_prft {5} 8. _temporary_;&lt;BR /&gt;&amp;nbsp; set WORK.ROLLIMG_STANDARD_DEVIATION;&lt;BR /&gt;&amp;nbsp; by gvkey year;&lt;BR /&gt;&amp;nbsp; length std_prft 8;&lt;BR /&gt;&amp;nbsp; retain std_calc_flag 0;&lt;BR /&gt;&amp;nbsp; element+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if element&amp;gt;dim(arr_prft) then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; element=1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; std_calc_flag=1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; arr_prft[element]=prft;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if std_calc_flag then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; std_prft=std(of arr_prft&lt;LI&gt;);&lt;/LI&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if last.gvkey then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; call missing(of _all_);&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Apr 2013 02:42:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-teh-rolling-standard-deviations/m-p/98386#M27684</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2013-04-05T02:42:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate teh  rolling standard deviations?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-teh-rolling-standard-deviations/m-p/98387#M27685</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Patrick,&lt;/P&gt;&lt;P&gt;Thanks. It is very likely I have missing years. If so, what kind of modifications should be?&lt;/P&gt;&lt;P&gt;Anna&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Apr 2013 02:46:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-teh-rolling-standard-deviations/m-p/98387#M27685</guid>
      <dc:creator>Anna_Guo</dc:creator>
      <dc:date>2013-04-05T02:46:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate teh  rolling standard deviations?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-teh-rolling-standard-deviations/m-p/98388#M27686</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Patrick,&lt;/P&gt;&lt;P&gt;Thanks. I think it is good enough for me.&lt;/P&gt;&lt;P&gt;Anna&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Apr 2013 02:51:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-teh-rolling-standard-deviations/m-p/98388#M27686</guid>
      <dc:creator>Anna_Guo</dc:creator>
      <dc:date>2013-04-05T02:51:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate teh  rolling standard deviations?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-teh-rolling-standard-deviations/m-p/98389#M27687</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;As Hai.kuo pointed out SAS/ETS procedures like Proc Expand and Proc Timeseries would do the job for you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For the code I've posted easiest would be to fix up the time series adding years with missing prices.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data All_Years(keep=gvkey year);&lt;BR /&gt;&amp;nbsp; set WORK.ROLLIMG_STANDARD_DEVIATION(keep=gvkey year);&lt;BR /&gt;&amp;nbsp; by gvkey year;&lt;BR /&gt;&amp;nbsp; lag_year=lag(year);&lt;BR /&gt;&amp;nbsp; source_year=year;&lt;BR /&gt;&amp;nbsp; if first.gvkey then output;&lt;BR /&gt;&amp;nbsp; else &lt;BR /&gt;&amp;nbsp; do year=lag_year+1 to source_year;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data want;&lt;BR /&gt;&amp;nbsp; array arr_prft {5} 8. _temporary_;&lt;BR /&gt;&amp;nbsp; merge WORK.ROLLIMG_STANDARD_DEVIATION All_Years;&lt;BR /&gt;&amp;nbsp; by gvkey year;&lt;BR /&gt;&amp;nbsp; length std_prft 8;&lt;BR /&gt;&amp;nbsp; retain std_calc_flag 0;&lt;BR /&gt;&amp;nbsp; element+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if element&amp;gt;dim(arr_prft) then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; element=1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; std_calc_flag=1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt; &lt;SPAN style="color: #ff0000;"&gt; if std_calc_flag then&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; std_prft=std(of arr_prft&lt;LI&gt;);&lt;/LI&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;&amp;nbsp; arr_prft[element]=prft;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if last.gvkey then&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; call missing(of _all_);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There was a logical error in my code. Please note that the calculation for the standard deviation must come BEFORE assigning the current prft to the array element.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Apr 2013 03:26:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-teh-rolling-standard-deviations/m-p/98389#M27687</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2013-04-05T03:26:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate teh  rolling standard deviations?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-teh-rolling-standard-deviations/m-p/98390#M27688</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Patrick,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a similar question but a little bit different Anna_Guo's. Could you also please help me to have a look?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A __default_attr="195683" __jive_macro_name="message" class="jive_macro jive_macro_message" href="https://communities.sas.com/"&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Feb 2014 01:13:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-teh-rolling-standard-deviations/m-p/98390#M27688</guid>
      <dc:creator>comeon2012</dc:creator>
      <dc:date>2014-02-04T01:13:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to calculate teh  rolling standard deviations?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-teh-rolling-standard-deviations/m-p/98391#M27689</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm sure Ksharp's answer will solve your problem beautifully. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 04 Feb 2014 05:48:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-calculate-teh-rolling-standard-deviations/m-p/98391#M27689</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2014-02-04T05:48:02Z</dc:date>
    </item>
  </channel>
</rss>

