<?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 change this macro? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-this-macro/m-p/860900#M340070</link>
    <description>&lt;P&gt;Maxim 9: There Is a Function for It.&lt;/P&gt;
&lt;P&gt;Instead of using the MEANS procedure, use the STD function on an array.&lt;/P&gt;
&lt;P&gt;This is an example of using an array for any kind of rolling window calculations&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let winsize=252;

data want;
set have;
by isin;
array vals {&amp;amp;winsize.} _temporary_;
if first.isin then call missing(of vals{*});
vals{mod(_n_,&amp;amp;winsize.)+1} = x;
sd&amp;amp;winsize. = std(of vals{*});
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested; for tested code, supply example data in a data step with datalines.&lt;/P&gt;</description>
    <pubDate>Sun, 26 Feb 2023 07:27:41 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2023-02-26T07:27:41Z</dc:date>
    <item>
      <title>How to change this macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-this-macro/m-p/860897#M340067</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;STRONG&gt;&lt;SPAN&gt;The macro below shows how you can compute a "rolling" standard deviation. For example, it gets the standard deviation for observations 1-25, then &lt;BR /&gt;observations 2-26 then 3-27 … up to 476-500, and then saves this into a SAS data file.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;%macro rollsd;

  proc delete data=all;
  run;

  %do firstobs = 1 %to 476;
    %let lastobs = %eval( &amp;amp;firstobs + 24);
    proc means data=test(firstobs=&amp;amp;firstobs obs=&amp;amp;lastobs);
      var x;
      output out=tempfile stddev=sd25;
    run;

    proc append base=all data=tempfile ;
    run;
  %end;

%mend rollsd;&lt;BR /&gt;&lt;BR /&gt;&lt;/STRONG&gt;I have hundreds of firms (ISIN) and each firm has different number of observations. This macro only considers the first observations from 1 to 476. &lt;BR /&gt;How do i adjust this macro so that i can calculate 252 day rolling standard deviation for all firms in my dataset? Thanks in advance for your help?&lt;/PRE&gt;</description>
      <pubDate>Sun, 26 Feb 2023 06:29:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-this-macro/m-p/860897#M340067</guid>
      <dc:creator>bd_user_10</dc:creator>
      <dc:date>2023-02-26T06:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to change this macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-this-macro/m-p/860900#M340070</link>
      <description>&lt;P&gt;Maxim 9: There Is a Function for It.&lt;/P&gt;
&lt;P&gt;Instead of using the MEANS procedure, use the STD function on an array.&lt;/P&gt;
&lt;P&gt;This is an example of using an array for any kind of rolling window calculations&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let winsize=252;

data want;
set have;
by isin;
array vals {&amp;amp;winsize.} _temporary_;
if first.isin then call missing(of vals{*});
vals{mod(_n_,&amp;amp;winsize.)+1} = x;
sd&amp;amp;winsize. = std(of vals{*});
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Untested; for tested code, supply example data in a data step with datalines.&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2023 07:27:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-this-macro/m-p/860900#M340070</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-02-26T07:27:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to change this macro?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-change-this-macro/m-p/860936#M340082</link>
      <description>&lt;P&gt;Do you have SAS/ETS licensed?&amp;nbsp; If so there is PROC for doing that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Feb 2023 14:53:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-change-this-macro/m-p/860936#M340082</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-02-26T14:53:19Z</dc:date>
    </item>
  </channel>
</rss>

