<?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: Obtaining single summary report from DO LOOPS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Obtaining-single-summary-report-from-DO-LOOPS/m-p/328674#M73391</link>
    <description>&lt;P&gt;Totally agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;, post test data, required output, code, logs etc so we can understand your question.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A question from my side however, why are you doing loops over the same code/data? &amp;nbsp;SAS is built around the concept of by group processing. &amp;nbsp;So an example, I could do this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%do i=1 to 2;
&amp;nbsp; proc print data=sashelp.class;
&amp;nbsp; &amp;nbsp; where code=&amp;amp;i.;
&amp;nbsp; &amp;nbsp; title "&amp;amp;i";
&amp;nbsp; run;
%end;&lt;/PRE&gt;
&lt;P&gt;Or you could use built in by group processing:&lt;/P&gt;
&lt;PRE&gt;proc print data=sashelp.class;
  by code;
  title "#byval1";
run;&lt;/PRE&gt;</description>
    <pubDate>Tue, 31 Jan 2017 09:44:19 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-01-31T09:44:19Z</dc:date>
    <item>
      <title>Obtaining single summary report from DO LOOPS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtaining-single-summary-report-from-DO-LOOPS/m-p/328626#M73378</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have performed a minimization pro0cedure in several DO LOOPS and have got out estimates for each loop. Now, I want to obtain a single summary report for all the out estimates from all the DO LOOPS. &amp;nbsp;Can somebody guide me the procedure for it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 00:00:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtaining-single-summary-report-from-DO-LOOPS/m-p/328626#M73378</guid>
      <dc:creator>Amalik</dc:creator>
      <dc:date>2017-01-31T00:00:53Z</dc:date>
    </item>
    <item>
      <title>Re: Obtaining single summary report from DO LOOPS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtaining-single-summary-report-from-DO-LOOPS/m-p/328635#M73379</link>
      <description>&lt;P&gt;Are you speaking of macro do loops?&amp;nbsp; in which proc's are run to generate your iterative estimates?&amp;nbsp; Or perhap regular do loops in a data step?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How about less mind reading from the volunteers on the forum and more information from you about the problem?&amp;nbsp; In particular the sas code by which you generate the iterative estimates you wish to summarize.&amp;nbsp; And also a clearer definition of what you mean by "summary report", even if what you mean is nothing more then a the&amp;nbsp;sequence of estimates all in a single report.&amp;nbsp; (After all many optimization/minimization procedures report not only estimates, but also gradients, and other attributes of the problem structure).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Jan 2017 03:49:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtaining-single-summary-report-from-DO-LOOPS/m-p/328635#M73379</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-01-31T03:49:46Z</dc:date>
    </item>
    <item>
      <title>Re: Obtaining single summary report from DO LOOPS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtaining-single-summary-report-from-DO-LOOPS/m-p/328674#M73391</link>
      <description>&lt;P&gt;Totally agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;, post test data, required output, code, logs etc so we can understand your question.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A question from my side however, why are you doing loops over the same code/data? &amp;nbsp;SAS is built around the concept of by group processing. &amp;nbsp;So an example, I could do this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%do i=1 to 2;
&amp;nbsp; proc print data=sashelp.class;
&amp;nbsp; &amp;nbsp; where code=&amp;amp;i.;
&amp;nbsp; &amp;nbsp; title "&amp;amp;i";
&amp;nbsp; run;
%end;&lt;/PRE&gt;
&lt;P&gt;Or you could use built in by group processing:&lt;/P&gt;
&lt;PRE&gt;proc print data=sashelp.class;
  by code;
  title "#byval1";
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 31 Jan 2017 09:44:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtaining-single-summary-report-from-DO-LOOPS/m-p/328674#M73391</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-31T09:44:19Z</dc:date>
    </item>
    <item>
      <title>Re: Obtaining single summary report from DO LOOPS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtaining-single-summary-report-from-DO-LOOPS/m-p/332045#M74701</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Apologies for getting back late. I have attached my data file and the code is inserted below. I ran a macro do loop and created a rolling regression. My data genrated 36 rolling windowsand for each window, I got a set of parameter estimates. Now what I want is a single summary report for the 36 rolling windows with its parameter estimates, var, standard deviation, R square etc (maybe a kind of average results across the rolling windows).. It wou7ld be great if you can guide me through that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc import datafile="C:\Users\amalik\Desktop\STYLEDATA1.csv"
     out=return
     dbms=csv
     replace;
     getnames=yes;
run;

data return2;
set work.return;
FORMAT Date date9.;
run;

title ' data return2 ';
proc print;run;

* Macro with parameters;
%MACRO RW (data=  ,out_ds= ,model_equation= ,permno=  , date= ,STARTd=  ,ENDd= ,regprint=);

%DO i=1 %TO 72; /*8*12NUMBER OF 36th month rolling window */ 
                       /* all the dates available so 107 covers the whole period*/

 /* dm log 'clear';
        dm 'odsresults; clear';
*/

  %let Date = %Sysfunc( InputN( 01nov2007 ,Date9.)) ; /*to create a macro variable for reference date which is the beginning of the rolling window date*/
    %let dated = %Sysfunc( PutN( &amp;amp;date , Date9.)) ; /*to input date and give it format by putn*/
     %put Date = &amp;amp;Date ;
      %put Dated = &amp;amp;Dated;

%IF &amp;amp;i =1 %THEN %DO;
 
 %let START = %Sysfunc( InputN( 01nov2007, Date9. )) ; /*to create a macro variable for reference date which is the beginning of the rolling window date*/
    %let STARTd = %Sysfunc( PutN( &amp;amp;start , Date9.)) ; /*to input date by input and give it format by putn*/
     %put START = &amp;amp;START ;
      %put STARTd = &amp;amp;STARTd;

%let END= %Sysfunc( Intnx( Month , &amp;amp;start , 35,end )) ;
 %let  ENDd=%Sysfunc( PutN( &amp;amp;END , Date9.)) ;
  %put end   = &amp;amp;end;
  %put endd  = &amp;amp;endd;

%GOTO CONTINUE;/*TO SEND THE FIRST WINDOW(DATE) TO THE NEXT STEP WHICH IS SQL FOR SUBSETTING THE MAIN DATA*/

%END;

%Else %IF &amp;amp;i&amp;gt;1 %THEN %DO;
 
%let Start = %Sysfunc( Intnx( month, &amp;amp;Date ,&amp;amp;i-1)) ;/*to specify intervals with intnx ,start should be 1 month after the previouse starting date*/
 %let End = %Sysfunc( Intnx( Month , &amp;amp;start , 35,end)) ;/*monthly interval for end to specify 36 rolling window*/
  %put start = &amp;amp;start
        end = &amp;amp;end;

%let STARTd=%Sysfunc( PutN( &amp;amp;START , Date9.)) ; /*to get DATE9. FORMAT FOR date instead of default date*/ 
 %let  ENDd=%Sysfunc( PutN( &amp;amp;END , Date9.)) ;
  %PUT STARTd=&amp;amp;STARTd  
        ENDd=&amp;amp;ENDd;

%continue:

proc sql  NOPRINT; /* TO SUBSET OUR COMPLETE DATASET IN ACCORDANCE TO THE ROLLING WINDOWS INTERVALS*/
 create table temp1 as
 select*
 from work.return2
 where DATE BETWEEN "&amp;amp;STARTd"d and "&amp;amp;ENDd"d;
 quit;


/*1-2: RUNNING multiple regression/PER INTERVALS out EACH TIME*/*********************************************;

proc reg data=temp1 noprint outest=Out_Estimates ;
proc corr data=temp1 (drop=date)
   out=corrout(where=(_type_ ne 'CORR')) cov noprint;
run;

data stats(drop=_name_);
   set corrout;
   if _type_ = 'COV' then delete;
run;
proc transpose data=stats out=stats;
   id _type_;
run;

proc optmodel;
   /* declare parameters and read data */
   set &amp;lt;str&amp;gt; ASSETS;
   str target = 'AMP_AIT';
   set BENCH = ASSETS diff {target};
   num cov {ASSETS, ASSETS};
   read data stats into ASSETS=[_name_];
   read data corrout(where=(_type_='COV')) into [_name_]
      {i in ASSETS} &amp;lt;cov[_name_,i]=col(i)&amp;gt;;
/* let w1, w2, w3, w4 be the amount invested in each asset */
   var x{1..4} &amp;gt;= 0;
   /* declare optimization model */
   var W {BENCH} &amp;gt;= 0 &amp;lt;= 1;
   /* Var(X - Y) = Var(X) + Var(Y) - 2 Cov(X,Y) */
   min Variance = 
      sum {i in BENCH, j in BENCH} cov[i,j] * W[i] * W[j]
    + cov[target,target] 
    - 2 * sum {i in BENCH} cov[i,target] * W[i];
	/* subject to the following constraints */
    con weights:  sum {i in BENCH} W[i] = 1;

   /* call solver and print optimal solution */
   solve;
   print W;
quit;

%END; 

* Show INPUT data this regression: ;
title 'Temp1, loop ' &amp;amp;i ;
proc print data=temp1; RUN; 
title1 'Merged Results';
proc means data=temp1
n mean var std stderr;
var US_Small_Val US_Small_Gr US_Large_Gr _US_Large_Val;
run;


%END;
%MEND RW;


*Invoke the macro;
%RW (data= work.return2 ,
out_ds= work.temp1,
model_equation= AMP_AIT = US_Small_Val US_Small_Gr US_Large_Gr _US_Large_Val /noint ,
permno= 1 , date=date ,
STARTd= 01nov2007 ,
ENDd= 01sep2016,
regprint=noprint)
; QUIT;

&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Feb 2017 01:26:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtaining-single-summary-report-from-DO-LOOPS/m-p/332045#M74701</guid>
      <dc:creator>Amalik</dc:creator>
      <dc:date>2017-02-13T01:26:43Z</dc:date>
    </item>
    <item>
      <title>Re: Obtaining single summary report from DO LOOPS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Obtaining-single-summary-report-from-DO-LOOPS/m-p/332046#M74702</link>
      <description>&lt;P&gt;Oh, just to correct myself. window size is 36 which generates 72 loops for my data not 36 loops.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2017 01:51:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Obtaining-single-summary-report-from-DO-LOOPS/m-p/332046#M74702</guid>
      <dc:creator>Amalik</dc:creator>
      <dc:date>2017-02-13T01:51:19Z</dc:date>
    </item>
  </channel>
</rss>

