<?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: rolling window in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/rolling-window/m-p/313642#M16516</link>
    <description>&lt;PRE&gt;
Skeleton code like:

data have;
input start date9.;
end=intnx('month',start,36,'s');
cards;
01jan2016
.......
;
run;

%macro xx(start=,end=);
 proc reg data=x(where=(date between &amp;amp;start and &amp;amp;end));
..........
%mend;

data _null_;
 set have;
 call execute('%xx(start='||start||',end='||end||')');
run;
&lt;/PRE&gt;</description>
    <pubDate>Wed, 23 Nov 2016 03:10:50 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-11-23T03:10:50Z</dc:date>
    <item>
      <title>rolling window</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/rolling-window/m-p/313630#M16515</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone guide me on how to create a rolling window regression and create a start and end date from the date variable with the window of 36 months. I have attached the data for reference?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Anum&lt;/P&gt;</description>
      <pubDate>Wed, 23 Nov 2016 01:50:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/rolling-window/m-p/313630#M16515</guid>
      <dc:creator>Amalik</dc:creator>
      <dc:date>2016-11-23T01:50:37Z</dc:date>
    </item>
    <item>
      <title>Re: rolling window</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/rolling-window/m-p/313642#M16516</link>
      <description>&lt;PRE&gt;
Skeleton code like:

data have;
input start date9.;
end=intnx('month',start,36,'s');
cards;
01jan2016
.......
;
run;

%macro xx(start=,end=);
 proc reg data=x(where=(date between &amp;amp;start and &amp;amp;end));
..........
%mend;

data _null_;
 set have;
 call execute('%xx(start='||start||',end='||end||')');
run;
&lt;/PRE&gt;</description>
      <pubDate>Wed, 23 Nov 2016 03:10:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/rolling-window/m-p/313642#M16516</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-23T03:10:50Z</dc:date>
    </item>
    <item>
      <title>Re: rolling window</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/rolling-window/m-p/314703#M16576</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please tell me where I am making mistake as the following code isn't working,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc import datafile="C:\Users\amalik\Desktop\STYLEDATA1.csv"&lt;BR /&gt;out=return&lt;BR /&gt;dbms=csv&lt;BR /&gt;replace;&lt;BR /&gt;getnames=yes;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro rollingreg&lt;BR /&gt;(data= work.return,&lt;BR /&gt;out_ds= work.returnout ,&lt;BR /&gt;model_equation= AMP_AIT = US_Small_Val US_Small_Gr US_Large_Gr US_Large_Val /noint&lt;BR /&gt;,id=permno , date=date ,&lt;BR /&gt;start_date=11/01/2007 ,&lt;BR /&gt;end_date=09/01/2016 ,&lt;BR /&gt;freq=month, s=1, n=36,&lt;BR /&gt;regprint=yes);&lt;BR /&gt;* Start with empty output data sets;&lt;BR /&gt;proc datasets nolist;&lt;BR /&gt;delete _all_ds _outest_ds;&lt;BR /&gt;run;&lt;BR /&gt;* Prepare input data for by-id-date use;&lt;BR /&gt;proc sort data=&amp;amp;data;&lt;BR /&gt;by &amp;amp;id &amp;amp;date;&lt;BR /&gt;run;&lt;BR /&gt;* Set the 'by-id' variable;&lt;BR /&gt;%let by_id= permno ; *blank default, no by variable;&lt;BR /&gt;%if %length(&amp;amp;id) &amp;gt; 0 %then %let by_id= by &amp;amp;id;&lt;BR /&gt;%* Determine date range variables;&lt;BR /&gt;%let sdate1 = &amp;amp;start_date;&lt;BR /&gt;%let sdate2 = &amp;amp;end_date;&lt;BR /&gt;%* Make start and end date if missing;&lt;BR /&gt;%if &amp;amp;start_date = %str() | &amp;amp;end_date = %str() %then %do;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;create table _dx1 as&lt;BR /&gt;select min(&amp;amp;date) as min_date, max(&amp;amp;date) as max_date&lt;BR /&gt;from &amp;amp;data where not missing(&amp;amp;date);&lt;BR /&gt;select min_date into : min_date from _dx1;&lt;BR /&gt;select max_date into : max_date from _dx1;&lt;BR /&gt;quit;&lt;BR /&gt;%end;&lt;BR /&gt;%* SDATE1 and SDATE2 put in sas date number form (1/1/1960=0);&lt;BR /&gt;%if &amp;amp;sdate1 = %str() %then %do;&lt;BR /&gt;%let sdate1= &amp;amp;min_date;&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&lt;BR /&gt;%if (%index(&amp;amp;sdate1,%str(-)) &amp;gt; 1) | (%index(&amp;amp;sdate1,%str(/)) &amp;gt; 1)&lt;BR /&gt;%then %let sdate1= %sysfunc(inputn(&amp;amp;sdate1,mmddyy10.));&lt;BR /&gt;%else %if ( %length(&amp;amp;sdate1)=7 )&lt;BR /&gt;%then %let sdate1= %sysfunc(inputn(01&amp;amp;sdate1,date9.));&lt;BR /&gt;%else %if ( %length(&amp;amp;sdate1)=8 | %length(&amp;amp;sdate1)=9 )&lt;BR /&gt;%then %let sdate1= %sysfunc(inputn(&amp;amp;sdate1,date9.));&lt;BR /&gt;%else %if ( %length(&amp;amp;sdate1)=4 )&lt;BR /&gt;%then %let sdate1= %sysfunc(inputn(01JAN&amp;amp;sdate1,date9.));&lt;BR /&gt;%if &amp;amp;year_date=1 %then %let sdate1=%sysfunc(year(&amp;amp;sdate1));&lt;BR /&gt;%end;&lt;BR /&gt;%if &amp;amp;sdate2 = %str() %then %do;&lt;BR /&gt;%let sdate2= &amp;amp;max_date;&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&lt;BR /&gt;%if (%index(&amp;amp;sdate2,%str(-)) &amp;gt; 1) | (%index(&amp;amp;sdate2,%str(/)) &amp;gt; 1)&lt;BR /&gt;%then %let sdate2= %sysfunc(inputn(&amp;amp;sdate2,mmddyy10.));&lt;BR /&gt;%else %if ( %length(&amp;amp;sdate2)=7 ) %then %do;&lt;BR /&gt;%let sdate2= %sysfunc(inputn(01&amp;amp;sdate2,date9.));&lt;BR /&gt;%let sdate2= %sysfunc(intnx(month,&amp;amp;sdate2,0,end));&lt;BR /&gt;%end;&lt;BR /&gt;%else %if ( %length(&amp;amp;sdate2)=8 | %length(&amp;amp;sdate2)=9 )&lt;BR /&gt;%then %let sdate2= %sysfunc(inputn(&amp;amp;sdate2,date9.));&lt;BR /&gt;%else %if ( %length(&amp;amp;sdate2)=4 )&lt;BR /&gt;%then %let sdate2= %sysfunc(inputn(31DEC&amp;amp;sdate2,date9.));&lt;BR /&gt;%if &amp;amp;year_date=1 %then %let sdate2=%sysfunc(year(&amp;amp;sdate2));&lt;BR /&gt;%end;&lt;BR /&gt;%*Determine loop frequency parameters;&lt;BR /&gt;%if %eval(&amp;amp;n)= 0 %then %let n= &amp;amp;s;&lt;BR /&gt;%* if n blank use 1 period (=&amp;amp;s) assumption;&lt;BR /&gt;%if &amp;amp;year_date=1 %then %let freq=year;&lt;BR /&gt;%* year frequency case;&lt;BR /&gt;%put Date variable: &amp;amp;date year_date: &amp;amp;year_date;&lt;BR /&gt;%put Start and end dates: &amp;amp;start_date &amp;amp;end_date // &amp;amp;sdate1 &amp;amp;sdate2;&lt;BR /&gt;%if &amp;amp;year_date=0 %then&lt;BR /&gt;%put %sysfunc(putn(&amp;amp;sdate1,date9.)) %sysfunc(putn(&amp;amp;sdate2,date9.));&lt;BR /&gt;%put Freq: &amp;amp;freq s: &amp;amp;s n: &amp;amp;n;&lt;BR /&gt;%* Preliminary date setting for each iteration/loop;&lt;BR /&gt;%* First end date (idate2) is n periods after the start date;&lt;BR /&gt;%if &amp;amp;year_date=1 %then %let idate2= %eval(&amp;amp;sdate1+(&amp;amp;n-1));&lt;BR /&gt;%else %let idate2= %sysfunc(intnx(&amp;amp;freq,&amp;amp;sdate1,(&amp;amp;n-1),end));&lt;BR /&gt;%if &amp;amp;year_date=0 %then %let idate1= %sysfunc(intnx(&amp;amp;freq,&amp;amp;idate2,-&amp;amp;n+1,begin));&lt;BR /&gt;%else %let idate1= %eval(&amp;amp;idate2-&amp;amp;n+1);&lt;BR /&gt;%put First loop: &amp;amp;idate1 -- &amp;amp;idate2;&lt;BR /&gt;%put Loop through: &amp;amp;sdate2;&lt;BR /&gt;%if (&amp;amp;idate2 &amp;gt; &amp;amp;sdate2) %then %do;&lt;BR /&gt;%* Dates are not acceptable-- show problem, do not run loop;&lt;BR /&gt;%put PROBLEM-- end date for loop exceeds range : ( &amp;amp;idate2 &amp;gt; &amp;amp;sdate2 );&lt;BR /&gt;%end;&lt;BR /&gt;%else %do; *Dates are accepted-- run loops;&lt;BR /&gt;%let jj=0;&lt;BR /&gt;%do %while(&amp;amp;idate2 &amp;lt;= &amp;amp;sdate2);&lt;BR /&gt;%let jj=%eval(&amp;amp;jj+1);&lt;BR /&gt;%*Define loop start date (idate1) based on inherited end date (idate2);&lt;BR /&gt;%if &amp;amp;year_date=0 %then %do;&lt;BR /&gt;%let idate1= %sysfunc(intnx(&amp;amp;freq,&amp;amp;idate2,-&amp;amp;n+1,begin));&lt;BR /&gt;%let date1c= %sysfunc(putn(&amp;amp;idate1,date9.));&lt;BR /&gt;%let date2c= %sysfunc(putn(&amp;amp;idate2,date9.));&lt;BR /&gt;%end;&lt;BR /&gt;%if &amp;amp;year_date=1 %then %do;&lt;BR /&gt;%let idate1= %eval(&amp;amp;idate2-&amp;amp;n+1);&lt;BR /&gt;%let date1c= &amp;amp;idate1;&lt;BR /&gt;%let date2c= &amp;amp;idate2;&lt;BR /&gt;%end;&lt;BR /&gt;%let idate1= %sysfunc(max(&amp;amp;sdate1,&amp;amp;idate1));&lt;BR /&gt;%put Loop: &amp;amp;jj -- &amp;amp;date1c &amp;amp;date2c;&lt;BR /&gt;%put &amp;amp;jj -- &amp;amp;idate1 &amp;amp;idate2;&lt;BR /&gt;proc datasets nolist;&lt;BR /&gt;delete _outest_ds;&lt;BR /&gt;run;&lt;BR /&gt;%***** analysis code here -- for each loop;&lt;BR /&gt;%* noprint to just make output set;&lt;BR /&gt;%let noprint= noprint;&lt;BR /&gt;%if %upcase(®print) = yes | %upcase(®print) = print %then %let noprint= ;&lt;BR /&gt;proc reg data=&amp;amp;data&lt;BR /&gt;outest=_outest_ds edf&lt;BR /&gt;&amp;amp;noprint;&lt;BR /&gt;where &amp;amp;date between &amp;amp;idate1 and &amp;amp;idate2;&lt;BR /&gt;model &amp;amp;model_equation;&lt;BR /&gt;&amp;amp;by_id;&lt;BR /&gt;run;&lt;BR /&gt;%* Add loop date range variables to output set;&lt;BR /&gt;data _outest_ds;&lt;BR /&gt;set _outest_ds;&lt;BR /&gt;regobs= _p_ + _edf_; %* number of observations in regression;&lt;BR /&gt;date1= &amp;amp;idate1;&lt;BR /&gt;date2= &amp;amp;idate2;&lt;BR /&gt;%if &amp;amp;year_date=0 %then format date1 date2 date9.;&lt;BR /&gt;run;&lt;BR /&gt;%* Append results;&lt;BR /&gt;proc datasets nolist;&lt;BR /&gt;append base=_all_ds data=_outest_ds;&lt;BR /&gt;run;&lt;BR /&gt;%* Set next loop end date;&lt;BR /&gt;%if &amp;amp;year_date=0 %then %let idate2= %sysfunc(intnx(&amp;amp;freq,&amp;amp;idate2,&amp;amp;s,end));&lt;BR /&gt;%else %if &amp;amp;year_date=1 %then %let idate2= %eval(&amp;amp;idate2+&amp;amp;s);&lt;BR /&gt;%end; *% end of loop;&lt;BR /&gt;%* Save outout set to desired location;&lt;BR /&gt;data &amp;amp;out_ds;&lt;BR /&gt;set _all_ds;&lt;BR /&gt;run;&lt;BR /&gt;proc sort data=&amp;amp;out_ds;&lt;BR /&gt;by &amp;amp;id date2;&lt;BR /&gt;run;&lt;BR /&gt;%end; %* end for date check pass section;&lt;BR /&gt;%mend;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Nov 2016 02:28:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/rolling-window/m-p/314703#M16576</guid>
      <dc:creator>Amalik</dc:creator>
      <dc:date>2016-11-28T02:28:05Z</dc:date>
    </item>
    <item>
      <title>Re: rolling window</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/rolling-window/m-p/314706#M16577</link>
      <description>&lt;PRE&gt;
Sorry. Your code is way too long.  I have no time to go through all of these.
I suggest you post a brand new session. Let others see your question.

I found a problem in your code:
model_equation= AMP_AIT = US_Small_Val US_Small_Gr US_Large_Gr US_Large_Val /noint

is not right which contain '=' in macro variable.
should something like:
model_equation=%str( AMP_AIT = US_Small_Val US_Small_Gr US_Large_Gr US_Large_Val /noint  )

&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Nov 2016 03:01:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/rolling-window/m-p/314706#M16577</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-11-28T03:01:23Z</dc:date>
    </item>
  </channel>
</rss>

