<?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: window rolling regression with irregular date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/window-rolling-regression-with-irregular-date/m-p/804655#M316893</link>
    <description>Sorry the beta should be -6.349044 (with stderr= 0.179827 ) of industry A in 2009/12/31 using the observation 3-22 (in 2007/1/1 to 2009/12/31); but anyhow, i want to execute a macro, say %regfun(dependent= independent= ) for each industry and date, how to insert it？</description>
    <pubDate>Tue, 29 Mar 2022 03:25:46 GMT</pubDate>
    <dc:creator>Xiyuan</dc:creator>
    <dc:date>2022-03-29T03:25:46Z</dc:date>
    <item>
      <title>window rolling regression with irregular date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/window-rolling-regression-with-irregular-date/m-p/804522#M316835</link>
      <description>&lt;P&gt;Hi all, I have a problem in make it faster when regressing using rolling window&amp;nbsp;&lt;/P&gt;&lt;P&gt;first note:&lt;/P&gt;&lt;P&gt;1. The&lt;STRONG&gt; date&lt;/STRONG&gt; has no definite cycle, but commonly two or four records a year, but allow a large gap&lt;/P&gt;&lt;P&gt;2. Industry can be not just a and b&lt;/P&gt;&lt;P&gt;3. for each date and each industry, y is product's price, there are N products, so y has three levels: y_(date,industry,product)&lt;/P&gt;&lt;P&gt;4. what we need: we need regress y on x of each each and industry&amp;nbsp;using window rolling&lt;/P&gt;&lt;P&gt;5. for example, if we use three years as window, we can calculate beta=-6.3352 (with stderr=0.181942) of industry A in 2009/12/31 using the observation 3-22 (in 2007/1/1 to 2009/12/31), we require the unique date records&amp;nbsp;of industry A within 3 years should at least 3*2=6, otherwise we will not estimate it, e.g., we don’t have enough observation of industry A in 2008/12/31, because there are only 5 unique date records only in 2006/1/1 to 2008/12/31&lt;/P&gt;&lt;P&gt;6. the rolling window can also be 1 year (require at least 2 unique date records) and 5 years (at least 5*2=10)&lt;/P&gt;</description>
      <pubDate>Mon, 28 Mar 2022 14:39:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/window-rolling-regression-with-irregular-date/m-p/804522#M316835</guid>
      <dc:creator>Xiyuan</dc:creator>
      <dc:date>2022-03-28T14:39:38Z</dc:date>
    </item>
    <item>
      <title>Re: window rolling regression with irregular date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/window-rolling-regression-with-irregular-date/m-p/804627#M316877</link>
      <description>&lt;P&gt;Here is one way to do this, using a SQL view to generate the regression windows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Window size in years */
%let window=2;

proc sql;
create view temp as
select 
    a.industry,
    a.product,
    a.date as refDate,
    b.date,
    b.x, b.y
from 
    have as a inner join
    have as b on a.industry=b.industry and a.product=b.product and
        b.date between intnx("year", a.date, -&amp;amp;window., "same") and a.date
group by a.industry, a.product, a.date
having count(distinct b.date) &amp;gt;= 2*&amp;amp;window.
order by industry, product, refDate, date;
quit;

/* For testing only: */
proc sql outobs=50;
select * from temp;
quit;

proc reg data=temp outest=want noprint;
by industry product refDate;
model y = x;
run;

proc print data=want(obs=5) noobs; 
var industry product refDate Intercept x; run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="PGStats_0-1648499412123.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/69892i2D79653E7B730D1A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="PGStats_0-1648499412123.png" alt="PGStats_0-1648499412123.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2022 00:54:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/window-rolling-regression-with-irregular-date/m-p/804627#M316877</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2022-03-29T00:54:40Z</dc:date>
    </item>
    <item>
      <title>Re: window rolling regression with irregular date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/window-rolling-regression-with-irregular-date/m-p/804629#M316878</link>
      <description>&lt;P&gt;PROC EXPAND can create a data set with regular date intervals from your data set that doesn't have regular date intervals. It's one way to proceed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Many of us will not download your Excel file, as it is a security risk. Please provide a portion of your data as text via SAS data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;instructions&lt;/A&gt;) and not as Excel file, not as screen captures.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Mar 2022 21:12:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/window-rolling-regression-with-irregular-date/m-p/804629#M316878</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-28T21:12:08Z</dc:date>
    </item>
    <item>
      <title>Re: window rolling regression with irregular date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/window-rolling-regression-with-irregular-date/m-p/804651#M316889</link>
      <description>&lt;P&gt;sorry, here is the txt.file, please check whether this works&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2022 02:42:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/window-rolling-regression-with-irregular-date/m-p/804651#M316889</guid>
      <dc:creator>Xiyuan</dc:creator>
      <dc:date>2022-03-29T02:42:41Z</dc:date>
    </item>
    <item>
      <title>Re: window rolling regression with irregular date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/window-rolling-regression-with-irregular-date/m-p/804655#M316893</link>
      <description>Sorry the beta should be -6.349044 (with stderr= 0.179827 ) of industry A in 2009/12/31 using the observation 3-22 (in 2007/1/1 to 2009/12/31); but anyhow, i want to execute a macro, say %regfun(dependent= independent= ) for each industry and date, how to insert it？</description>
      <pubDate>Tue, 29 Mar 2022 03:25:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/window-rolling-regression-with-irregular-date/m-p/804655#M316893</guid>
      <dc:creator>Xiyuan</dc:creator>
      <dc:date>2022-03-29T03:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: window rolling regression with irregular date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/window-rolling-regression-with-irregular-date/m-p/804656#M316894</link>
      <description>thanks this works well, but one question is I have so many observations, if I merge and regress for each block, the sample can be huger than the sky ,so it's better to use a loop to handle this problem</description>
      <pubDate>Tue, 29 Mar 2022 03:31:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/window-rolling-regression-with-irregular-date/m-p/804656#M316894</guid>
      <dc:creator>Xiyuan</dc:creator>
      <dc:date>2022-03-29T03:31:26Z</dc:date>
    </item>
    <item>
      <title>Re: window rolling regression with irregular date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/window-rolling-regression-with-irregular-date/m-p/804887#M316993</link>
      <description>&lt;P&gt;This version doesn't (in theory) create any huge dataset (at least it doesn't need to). Only testing will tell :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have out=haveSort(keep=industry product date x y); 
by industry product date; 
run;

data haveObs;
set haveSort;
obs = _n_;
run;

/* Window size in years */
%let window=2;

proc sql;
create table temp as
select 
    a.industry,
    a.product,
    a.date as refDate,
    min(b.obs) as startObs,
    max(b.obs) as endObs
from 
    haveObs as a inner join
    haveObs as b on a.industry=b.industry and a.product=b.product and
        b.date between intnx("year", a.date, -&amp;amp;window., "same") and a.date
group by a.industry, a.product, a.date
having count(distinct b.date) &amp;gt;= 2*&amp;amp;window.;
quit;

data inter / view=inter;
set temp;
do point = startObs to endObs;
    set haveObs point=point;
    output;
    end;
keep industry product refDate date x y;
run;

proc reg data=inter outest=want noprint;
by industry product refDate;
model y = x;
run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Mar 2022 20:46:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/window-rolling-regression-with-irregular-date/m-p/804887#M316993</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2022-03-29T20:46:18Z</dc:date>
    </item>
    <item>
      <title>Re: window rolling regression with irregular date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/window-rolling-regression-with-irregular-date/m-p/804889#M316994</link>
      <description>&lt;P&gt;I think this example using PROC EXPAND is where you should start. Once you handle the irregular dates, then you can try the rolling regressions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmmvacdc/9.4/etsug/etsug_expand_examples03.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmmvacdc/9.4/etsug/etsug_expand_examples03.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2022 20:55:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/window-rolling-regression-with-irregular-date/m-p/804889#M316994</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-29T20:55:44Z</dc:date>
    </item>
  </channel>
</rss>

