<?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 Rolling pairwise correlations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rolling-pairwise-correlations/m-p/325468#M72385</link>
    <description>&lt;P&gt;I'm looking to calculate rolling window pairwise correlations, something in SAS that replicates the following python function. Please let me know if you need data and more examples ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc IML &amp;nbsp;doesn't do the trick either :&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
	use work.ret_trans;
	read all var{date} into myDates;		
	read all var _NUM_ into X[colname=NumerNames];
do x=18 to nrow(myDates);
		dt=myDates[x];
		lagdt = intnx('month',dt,-18,'end');
		read all var _NUM_ where(date &amp;lt;= dt &amp;amp; date &amp;gt; lagdt ) into trailing18;
		
		idx = setdif(1:ncol(trailing18), 1); 
		
	pc = corr(trailing18);
	
	if x=18 then create work.PairWise from pc ;
		else edit work.PairWise ;
		append from pc;
	
  end;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;pandas.rolling_corr pandas.rolling_corr(&lt;EM&gt;arg1&lt;/EM&gt;, &lt;EM&gt;arg2=None&lt;/EM&gt;, &lt;EM&gt;window=None&lt;/EM&gt;, &lt;EM&gt;min_periods=None&lt;/EM&gt;, &lt;EM&gt;freq=None&lt;/EM&gt;, &lt;EM&gt;center=False&lt;/EM&gt;, &lt;EM&gt;pairwise=None&lt;/EM&gt;, &lt;EM&gt;how=None&lt;/EM&gt;)&lt;/P&gt;&lt;P&gt;Moving sample correlation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Parameters: Returns:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P class="first"&gt;&lt;STRONG&gt;arg1&lt;/STRONG&gt; : Series, DataFrame, or ndarray&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;arg2&lt;/STRONG&gt; : Series, DataFrame, or ndarray, optional&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;P&gt;if not supplied then will default to arg1 and produce pairwise output&lt;/P&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;STRONG&gt;window&lt;/STRONG&gt; : int&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;P&gt;Size of the moving window. This is the number of observations used for calculating the statistic.&lt;/P&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;STRONG&gt;min_periods&lt;/STRONG&gt; : int, default None&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;P&gt;Minimum number of observations in window required to have a value (otherwise result is NA).&lt;/P&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;STRONG&gt;freq&lt;/STRONG&gt; : string or DateOffset object, optional (default None)&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;P&gt;Frequency to conform the data to before computing the statistic. Specified as a frequency string or DateOffset object.&lt;/P&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;STRONG&gt;center&lt;/STRONG&gt; : boolean, default False&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;P&gt;Set the labels at the center of the window.&lt;/P&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;STRONG&gt;how&lt;/STRONG&gt; : string, default ‘None’&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;P&gt;Method for down- or re-sampling&lt;/P&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;STRONG&gt;pairwise&lt;/STRONG&gt; : bool, default False&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;P&gt;If False then only matching columns between arg1 and arg2 will be used and the output will be a DataFrame. If True then all pairwise combinations will be calculated and the output will be a Panel in the case of DataFrame inputs. In the case of missing elements, only complete pairwise observations will be used.&lt;/P&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P class="first"&gt;&lt;STRONG&gt;y&lt;/STRONG&gt; : type depends on inputs&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;P&gt;DataFrame / DataFrame -&amp;gt; DataFrame (matches on columns) or Panel (pairwise) DataFrame / Series -&amp;gt; Computes result for each column Series / Series -&amp;gt; Series&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
    <pubDate>Tue, 17 Jan 2017 20:50:43 GMT</pubDate>
    <dc:creator>mgm</dc:creator>
    <dc:date>2017-01-17T20:50:43Z</dc:date>
    <item>
      <title>Rolling pairwise correlations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-pairwise-correlations/m-p/325468#M72385</link>
      <description>&lt;P&gt;I'm looking to calculate rolling window pairwise correlations, something in SAS that replicates the following python function. Please let me know if you need data and more examples ?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc IML &amp;nbsp;doesn't do the trick either :&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
	use work.ret_trans;
	read all var{date} into myDates;		
	read all var _NUM_ into X[colname=NumerNames];
do x=18 to nrow(myDates);
		dt=myDates[x];
		lagdt = intnx('month',dt,-18,'end');
		read all var _NUM_ where(date &amp;lt;= dt &amp;amp; date &amp;gt; lagdt ) into trailing18;
		
		idx = setdif(1:ncol(trailing18), 1); 
		
	pc = corr(trailing18);
	
	if x=18 then create work.PairWise from pc ;
		else edit work.PairWise ;
		append from pc;
	
  end;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;pandas.rolling_corr pandas.rolling_corr(&lt;EM&gt;arg1&lt;/EM&gt;, &lt;EM&gt;arg2=None&lt;/EM&gt;, &lt;EM&gt;window=None&lt;/EM&gt;, &lt;EM&gt;min_periods=None&lt;/EM&gt;, &lt;EM&gt;freq=None&lt;/EM&gt;, &lt;EM&gt;center=False&lt;/EM&gt;, &lt;EM&gt;pairwise=None&lt;/EM&gt;, &lt;EM&gt;how=None&lt;/EM&gt;)&lt;/P&gt;&lt;P&gt;Moving sample correlation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Parameters: Returns:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P class="first"&gt;&lt;STRONG&gt;arg1&lt;/STRONG&gt; : Series, DataFrame, or ndarray&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;arg2&lt;/STRONG&gt; : Series, DataFrame, or ndarray, optional&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;P&gt;if not supplied then will default to arg1 and produce pairwise output&lt;/P&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;STRONG&gt;window&lt;/STRONG&gt; : int&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;P&gt;Size of the moving window. This is the number of observations used for calculating the statistic.&lt;/P&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;STRONG&gt;min_periods&lt;/STRONG&gt; : int, default None&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;P&gt;Minimum number of observations in window required to have a value (otherwise result is NA).&lt;/P&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;STRONG&gt;freq&lt;/STRONG&gt; : string or DateOffset object, optional (default None)&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;P&gt;Frequency to conform the data to before computing the statistic. Specified as a frequency string or DateOffset object.&lt;/P&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;STRONG&gt;center&lt;/STRONG&gt; : boolean, default False&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;P&gt;Set the labels at the center of the window.&lt;/P&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;STRONG&gt;how&lt;/STRONG&gt; : string, default ‘None’&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;P&gt;Method for down- or re-sampling&lt;/P&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;STRONG&gt;pairwise&lt;/STRONG&gt; : bool, default False&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;P&gt;If False then only matching columns between arg1 and arg2 will be used and the output will be a DataFrame. If True then all pairwise combinations will be calculated and the output will be a Panel in the case of DataFrame inputs. In the case of missing elements, only complete pairwise observations will be used.&lt;/P&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P class="first"&gt;&lt;STRONG&gt;y&lt;/STRONG&gt; : type depends on inputs&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;DIV&gt;&lt;P&gt;DataFrame / DataFrame -&amp;gt; DataFrame (matches on columns) or Panel (pairwise) DataFrame / Series -&amp;gt; Computes result for each column Series / Series -&amp;gt; Series&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Tue, 17 Jan 2017 20:50:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-pairwise-correlations/m-p/325468#M72385</guid>
      <dc:creator>mgm</dc:creator>
      <dc:date>2017-01-17T20:50:43Z</dc:date>
    </item>
    <item>
      <title>Re: Rolling pairwise correlations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rolling-pairwise-correlations/m-p/325493#M72390</link>
      <description>&lt;P&gt;If you have SAS/ETS software, you can use PROC EXPAND. See the second example in Vora (2008):&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/forum2008/093-2008.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/forum2008/093-2008.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A DATA step solution is provided in the same paper.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jan 2017 21:44:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rolling-pairwise-correlations/m-p/325493#M72390</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-01-17T21:44:39Z</dc:date>
    </item>
  </channel>
</rss>

