<?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: Need to calculate rolling standard deviation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-to-calculate-rolling-standard-deviation/m-p/710841#M218893</link>
    <description>Thank you very much for the codes.</description>
    <pubDate>Tue, 12 Jan 2021 16:03:39 GMT</pubDate>
    <dc:creator>bd_user_10</dc:creator>
    <dc:date>2021-01-12T16:03:39Z</dc:date>
    <item>
      <title>Need to calculate rolling standard deviation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-calculate-rolling-standard-deviation/m-p/698562#M213654</link>
      <description>&lt;P&gt;Hi&amp;nbsp;Everyone,&lt;/P&gt;&lt;P&gt;I need to calculate the rolling standard deviation of daily stock returns over one year prior to the trading day. I have been using the following codes but not sure whether it's working correctly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select *,(select std(stk_return) from daily_stock_return where date between a.date-252 and a.date-1 and isin=a.isin) as rolling_std&lt;BR /&gt;from daily_stock_return as a;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have assumed 252 working days in a year although it could be different in different years! May be there is a better way to deal with this. Any help would be appreciated. Please find the attached sample data. Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2020 01:18:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-calculate-rolling-standard-deviation/m-p/698562#M213654</guid>
      <dc:creator>bd_user_10</dc:creator>
      <dc:date>2020-11-13T01:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: Need to calculate rolling standard deviation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-calculate-rolling-standard-deviation/m-p/698569#M213656</link>
      <description>&lt;P&gt;Many good answers already exist.&amp;nbsp; Try googling:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;sas.com:rolling standard deviation&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2020 03:05:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-calculate-rolling-standard-deviation/m-p/698569#M213656</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2020-11-13T03:05:47Z</dc:date>
    </item>
    <item>
      <title>Re: Need to calculate rolling standard deviation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-calculate-rolling-standard-deviation/m-p/698588#M213669</link>
      <description>&lt;P&gt;Thanks for the advice!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, these codes creating the rolling standard deviation from day 2. How do I restrict it to have all 252 days observations to calculate the rolling standard deviation?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Nov 2020 08:19:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-calculate-rolling-standard-deviation/m-p/698588#M213669</guid>
      <dc:creator>bd_user_10</dc:creator>
      <dc:date>2020-11-13T08:19:22Z</dc:date>
    </item>
    <item>
      <title>Re: Need to calculate rolling standard deviation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-calculate-rolling-standard-deviation/m-p/698592#M213671</link>
      <description>&lt;P&gt;See if you can use this as a template&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create table want as
   select *, 
          (select std(close) from sashelp.stocks 
             where stock=a.stock
               and (intnx('month', a.Date, -12, 's') le Date le a.Date)) 
                 as std format=8.2
   from sashelp.stocks as a;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Nov 2020 08:27:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-calculate-rolling-standard-deviation/m-p/698592#M213671</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-13T08:27:42Z</dc:date>
    </item>
    <item>
      <title>Re: Need to calculate rolling standard deviation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-calculate-rolling-standard-deviation/m-p/699718#M214052</link>
      <description>&lt;P&gt;Below is a sample program tested using provided dataset.&lt;BR /&gt;I added year variable to original dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.daily_stock_return;
	set daily_stock_return;
	*added year variable;
	year=year(date);
run;

data want;
	do _N_=1 by 1 until(last.year);
		set work.daily_stock_return;
		by isin year notsorted;
		
		array days[999] _temporary_;
		days[_N_]=stk_return;
		rolling_std=std(of days[*]);
		
		if last.year then do i=1 to dim(days);
			days[i]=.;
		end;
		output;
	end;
	drop i year;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Nov 2020 09:36:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-calculate-rolling-standard-deviation/m-p/699718#M214052</guid>
      <dc:creator>hhinohar</dc:creator>
      <dc:date>2020-11-18T09:36:38Z</dc:date>
    </item>
    <item>
      <title>Re: Need to calculate rolling standard deviation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-to-calculate-rolling-standard-deviation/m-p/710841#M218893</link>
      <description>Thank you very much for the codes.</description>
      <pubDate>Tue, 12 Jan 2021 16:03:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-to-calculate-rolling-standard-deviation/m-p/710841#M218893</guid>
      <dc:creator>bd_user_10</dc:creator>
      <dc:date>2021-01-12T16:03:39Z</dc:date>
    </item>
  </channel>
</rss>

