<?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: Calculation of rolling standard deviation using PROC EXPAND in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Calculation-of-rolling-standard-deviation-using-PROC-EXPAND/m-p/256358#M57134</link>
    <description>&lt;P&gt;Proc Expand is an&amp;nbsp;undoubtedly&amp;nbsp;powerful utility tool, however, because it is not a programming tool, it lacks certain level of flexibility &amp;nbsp;that data step can conveniently offer.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input id date X;
	datalines;
1  194503  .
1  194506  .   
1  194509  0.1
2  194703  .
2  194706  0.2
2  194709  0.1
2  194712  0.3
2  194803  0.2
;

data want;
	array _sd(0:2) _temporary_;
	set have;
	by id date;

	if first.id then
		do;
			call missing(of _sd(*));
			_n=0;
		end;

	_n+1;
	_sd(mod(_n,3))=x;

	if n(of _sd(*))&amp;gt;=2 then
		stdx=std(of _sd(*));
		drop _n;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 13 Mar 2016 01:21:37 GMT</pubDate>
    <dc:creator>Haikuo</dc:creator>
    <dc:date>2016-03-13T01:21:37Z</dc:date>
    <item>
      <title>Calculation of rolling standard deviation using PROC EXPAND</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Calculation-of-rolling-standard-deviation-using-PROC-EXPAND/m-p/256331#M57129</link>
      <description>&lt;P&gt;Dear All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I have the following dataset:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
&amp;nbsp;&amp;nbsp; input id&amp;nbsp;date X;
datalines;
1  194503  .
1 &amp;nbsp;194506  . &amp;nbsp; 
1 &amp;nbsp;194509  0.1&lt;BR /&gt;2  194703  .
2 &amp;nbsp;194706  0.2
2 &amp;nbsp;194709  0.1&lt;BR /&gt;2  194712  0.3&lt;BR /&gt;2  194803  0.2;&lt;/PRE&gt;
&lt;P&gt;I would like to compute the rolling standard deviation (STDX) &amp;nbsp;for different IDs of the variable X using 3 observations (with no less than 2).&amp;nbsp;For example, in row 5 after two observations of X (0.2 and 0.1), I want to compute STDX as 0.05. In row 6, after three observations of X (0.2, 0.1 and 0.3), I wnat to compute STDX as 0.082&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
&amp;nbsp;&amp;nbsp; input id&amp;nbsp;date X STDX;
datalines;
1  194503  .    .
1 &amp;nbsp;194506  . &amp;nbsp;  .
1 &amp;nbsp;194509  0.1  .&lt;BR /&gt;2  194703  .    .
2 &amp;nbsp;194706  0.2  .
2 &amp;nbsp;194709  0.1  0.05&lt;BR /&gt;2  194712  0.3  0.082&lt;BR /&gt;2  194803  0.2  0.082;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My attempt involves proc expand as follows. Yet, I'm not able to get the desired result. Moreover, I'm also getting the following warning:&amp;nbsp;&lt;EM&gt;WARNING: The variable X&amp;nbsp;has only 0 nonmissing observations, which is too few to apply&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt; the conversion method. The result series is set to missing.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any help would be highly appreciated. Many thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;PROC EXPAND DATA=have OUT=want;
by id;
convert X=STDX / transformout=(MOVSTD 3 trim 2); 
RUN;&lt;/PRE&gt;</description>
      <pubDate>Sat, 12 Mar 2016 20:29:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Calculation-of-rolling-standard-deviation-using-PROC-EXPAND/m-p/256331#M57129</guid>
      <dc:creator>mark_ph</dc:creator>
      <dc:date>2016-03-12T20:29:49Z</dc:date>
    </item>
    <item>
      <title>Re: Calculation of rolling standard deviation using PROC EXPAND</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Calculation-of-rolling-standard-deviation-using-PROC-EXPAND/m-p/256358#M57134</link>
      <description>&lt;P&gt;Proc Expand is an&amp;nbsp;undoubtedly&amp;nbsp;powerful utility tool, however, because it is not a programming tool, it lacks certain level of flexibility &amp;nbsp;that data step can conveniently offer.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input id date X;
	datalines;
1  194503  .
1  194506  .   
1  194509  0.1
2  194703  .
2  194706  0.2
2  194709  0.1
2  194712  0.3
2  194803  0.2
;

data want;
	array _sd(0:2) _temporary_;
	set have;
	by id date;

	if first.id then
		do;
			call missing(of _sd(*));
			_n=0;
		end;

	_n+1;
	_sd(mod(_n,3))=x;

	if n(of _sd(*))&amp;gt;=2 then
		stdx=std(of _sd(*));
		drop _n;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 13 Mar 2016 01:21:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Calculation-of-rolling-standard-deviation-using-PROC-EXPAND/m-p/256358#M57134</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2016-03-13T01:21:37Z</dc:date>
    </item>
  </channel>
</rss>

