<?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: Abbreviation of long sums in proc model in SAS Forecasting and Econometrics</title>
    <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Abbreviation-of-long-sums-in-proc-model/m-p/392187#M2634</link>
    <description>&lt;P&gt;Thank you Puwang, but I receive the error 'The %DO statement is not valid in open code.'.&lt;BR /&gt;This is how I implemented the idea of yours:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%ODSOff;
proc model
		data	=	in;


        	endo 	=	y;
         	exog
				x_l1-x_l18
				month_indicator2-month_indicator192;

         	parms
				a
				b
				l
				t2-t192;



		mflow	 =
							a	+	

							b * (
							exp(-l*(0))*x_l1+
							exp(-l*(1))*x_l2+
							exp(-l*(2))*x_l3+
							exp(-l*(3))*x_l4+
							exp(-l*(4))*x_l5+
							exp(-l*(5))*x_l6+
							exp(-l*(6))*x_l7+
							exp(-l*(7))*x_l8+
							exp(-l*(8))*x_l9+
							exp(-l*(9))*x_l10+
							exp(-l*(10))*x_l11+
							exp(-l*(11))*x_l12+
							exp(-l*(12))*x_l13+
							exp(-l*(13))*x_l14+
							exp(-l*(14))*x_l15+
							exp(-l*(15))*x_l16+
							exp(-l*(16))*x_l17+
							exp(-l*(17))*x_l18)
	
							+	

							/* Your suggestion as I understood */
							%do i = 2 %to 191;
								t&amp;amp;i.*month_indicator&amp;amp;i. + 
							%end;
							t192*month_indicator192;

		 	fit mflow
				/ gmm;

		 	ods output
				ParameterEstimates			=	ParameterEstimates_sine_exp_x
				ResidSummary				=	ResidSummary_sine_exp_x;

run; quit;
%ODSOn;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yours sincereley&lt;/P&gt;&lt;P&gt;Sinistrum&lt;/P&gt;</description>
    <pubDate>Thu, 31 Aug 2017 13:26:36 GMT</pubDate>
    <dc:creator>Sinistrum</dc:creator>
    <dc:date>2017-08-31T13:26:36Z</dc:date>
    <item>
      <title>Abbreviation of long sums in proc model</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Abbreviation-of-long-sums-in-proc-model/m-p/392108#M2632</link>
      <description>&lt;P&gt;Dear community,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would be glad, if you were to provide help concerning my following issue.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Core of my question: Is there (an equivalent of) a sum operator in the "proc model" environment?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Explicit setting/example:&lt;/P&gt;&lt;P&gt;I am running the following regression, where I am trying to estimate the an exponential decay function, where y is assumed to be an exponentially weighted sum of lagged x-es.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="baseline model.PNG" style="width: 346px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/14747i6EAFE5515255D291/image-size/large?v=v2&amp;amp;px=999" role="button" title="baseline model.PNG" alt="baseline model.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%ODSOff;
proc model
		data	=	in;


        	endo 	=	y;
         	exog
				x_l1-x_l18;

         	parms
				a
				b
				l;



		mflow	 =
							a	+	

							b * (
							exp(-l*(0))*x_l1+
							exp(-l*(1))*x_l2+
							exp(-l*(2))*x_l3+
							exp(-l*(3))*x_l4+
							exp(-l*(4))*x_l5+
							exp(-l*(5))*x_l6+
							exp(-l*(6))*x_l7+
							exp(-l*(7))*x_l8+
							exp(-l*(8))*x_l9+
							exp(-l*(9))*x_l10+
							exp(-l*(10))*x_l11+
							exp(-l*(11))*x_l12+
							exp(-l*(12))*x_l13+
							exp(-l*(13))*x_l14+
							exp(-l*(14))*x_l15+
							exp(-l*(15))*x_l16+
							exp(-l*(16))*x_l17+
							exp(-l*(17))*x_l18);

		 	fit mflow
				/ gmm;

		 	ods output
				ParameterEstimates			=	ParameterEstimates_sine_exp_x
				ResidSummary				=	ResidSummary_sine_exp_x;

run; quit;
%ODSOn;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the skeleton of the model.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Next, I add covariates.&lt;/P&gt;&lt;P&gt;Among this, there are a many indicator variables.&lt;/P&gt;&lt;P&gt;E.g., I want to use "time dummies".&lt;/P&gt;&lt;P&gt;For the sake of it, please let us assume I do not want to de-mean, I like to have distinct coefficient estimates.&lt;/P&gt;&lt;P&gt;The sample has is that there are 192 time points, i.e. 192 indicator variables, i.e. 191 regressors for my model for I want to keep a, the model's intercept.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As of now, I used a very-quick-and-dirty-way: Generate a list of "t2*month_indicator2 + ... + t192*month_indicator192" conveniently in Excel and copy-paste it.&lt;/P&gt;&lt;P&gt;The code becomes even more messy than it already is.&lt;/P&gt;&lt;P&gt;Thus, I would like to have something like a sum-operator in the vein "sum from i=2 to 192: ti*month_indicatori".&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="timedummy model.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/14748iFA5E1C18AABDEF4F/image-size/large?v=v2&amp;amp;px=999" role="button" title="timedummy model.PNG" alt="timedummy model.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If it is of any importance, I am trying to replicate the method by Barber/Huang/Odean (2016) ("Which Factors Matter to Investors? Evidence from Mutual Fnd Flows") and it is ought to be equation (5).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yours sincerely&lt;/P&gt;&lt;P&gt;Sinistrum&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2017 06:22:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Abbreviation-of-long-sums-in-proc-model/m-p/392108#M2632</guid>
      <dc:creator>Sinistrum</dc:creator>
      <dc:date>2017-08-31T06:22:38Z</dc:date>
    </item>
    <item>
      <title>Re: Abbreviation of long sums in proc model</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Abbreviation-of-long-sums-in-proc-model/m-p/392181#M2633</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Sinistrum, you can use macro statement to generate the&amp;nbsp;summation list:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do i = 2 %to 191;
	t&amp;amp;i.*month_indicator&amp;amp;i. + 
%end;
t192*month_indicator192&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;The above statement will give you:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;t2*month_indicator2 + t3*month_indicator3 +... + t192*month_indicator192&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Hope this helps.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Pu&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2017 13:10:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Abbreviation-of-long-sums-in-proc-model/m-p/392181#M2633</guid>
      <dc:creator>Puwang</dc:creator>
      <dc:date>2017-08-31T13:10:03Z</dc:date>
    </item>
    <item>
      <title>Re: Abbreviation of long sums in proc model</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Abbreviation-of-long-sums-in-proc-model/m-p/392187#M2634</link>
      <description>&lt;P&gt;Thank you Puwang, but I receive the error 'The %DO statement is not valid in open code.'.&lt;BR /&gt;This is how I implemented the idea of yours:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%ODSOff;
proc model
		data	=	in;


        	endo 	=	y;
         	exog
				x_l1-x_l18
				month_indicator2-month_indicator192;

         	parms
				a
				b
				l
				t2-t192;



		mflow	 =
							a	+	

							b * (
							exp(-l*(0))*x_l1+
							exp(-l*(1))*x_l2+
							exp(-l*(2))*x_l3+
							exp(-l*(3))*x_l4+
							exp(-l*(4))*x_l5+
							exp(-l*(5))*x_l6+
							exp(-l*(6))*x_l7+
							exp(-l*(7))*x_l8+
							exp(-l*(8))*x_l9+
							exp(-l*(9))*x_l10+
							exp(-l*(10))*x_l11+
							exp(-l*(11))*x_l12+
							exp(-l*(12))*x_l13+
							exp(-l*(13))*x_l14+
							exp(-l*(14))*x_l15+
							exp(-l*(15))*x_l16+
							exp(-l*(16))*x_l17+
							exp(-l*(17))*x_l18)
	
							+	

							/* Your suggestion as I understood */
							%do i = 2 %to 191;
								t&amp;amp;i.*month_indicator&amp;amp;i. + 
							%end;
							t192*month_indicator192;

		 	fit mflow
				/ gmm;

		 	ods output
				ParameterEstimates			=	ParameterEstimates_sine_exp_x
				ResidSummary				=	ResidSummary_sine_exp_x;

run; quit;
%ODSOn;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yours sincereley&lt;/P&gt;&lt;P&gt;Sinistrum&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2017 13:26:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Abbreviation-of-long-sums-in-proc-model/m-p/392187#M2634</guid>
      <dc:creator>Sinistrum</dc:creator>
      <dc:date>2017-08-31T13:26:36Z</dc:date>
    </item>
    <item>
      <title>Re: Abbreviation of long sums in proc model</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Abbreviation-of-long-sums-in-proc-model/m-p/392189#M2635</link>
      <description>&lt;P&gt;You need to put it in a macro. Do the following outside your proc model statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro sum_script();
%do i = 2 %to 191;
	t&amp;amp;i.*month_indicator&amp;amp;i. +
%end;
t192*month_indicator192;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then call %sum_script; in proc model where you insert the&amp;nbsp;summation function.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2017 13:29:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Abbreviation-of-long-sums-in-proc-model/m-p/392189#M2635</guid>
      <dc:creator>Puwang</dc:creator>
      <dc:date>2017-08-31T13:29:52Z</dc:date>
    </item>
    <item>
      <title>Re: Abbreviation of long sums in proc model</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Abbreviation-of-long-sums-in-proc-model/m-p/392201#M2636</link>
      <description>&lt;P&gt;First, please excuse me for being clumsy,&lt;/P&gt;&lt;P&gt;second, thank you very much indeed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can make use of this at so many instances in my codes - I appreciate it a lot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yours sincerely&lt;/P&gt;&lt;P&gt;Sinistrum&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2017 14:01:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Abbreviation-of-long-sums-in-proc-model/m-p/392201#M2636</guid>
      <dc:creator>Sinistrum</dc:creator>
      <dc:date>2017-08-31T14:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: Abbreviation of long sums in proc model</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Abbreviation-of-long-sums-in-proc-model/m-p/392210#M2637</link>
      <description>&lt;P&gt;PROC MODEL provides many facilities for implementing models like this one.&amp;nbsp; Besides using macros you can use arrays, or the SUM function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc model ...;
   endo y;
   exog x1-x10 ind1-ind10;
   parms a l t1-t10;

   array t[10] t1-t10;
   array x[10] x1-x10;
   array ind[10] ind1-ind10;
   array tmp[10];

   do i = 1 to 10;
      tmp[i] = exp(-l*(i-1))*x[i]
               + t[i]*ind[i];              
   end;

   y = a + sum (of tmp1-tmp10);

   fit y;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 31 Aug 2017 14:09:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Abbreviation-of-long-sums-in-proc-model/m-p/392210#M2637</guid>
      <dc:creator>kessler</dc:creator>
      <dc:date>2017-08-31T14:09:12Z</dc:date>
    </item>
    <item>
      <title>Re: Abbreviation of long sums in proc model</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Abbreviation-of-long-sums-in-proc-model/m-p/392212#M2638</link>
      <description>&lt;P&gt;Glad that I can help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To make it more convenient, you can just wrap your entire proc model statement (or more code) within a macro, so that you do not need to create extra macros for each %do loop you created.&lt;/P&gt;
&lt;P&gt;For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro call_model();
proc model
		data	=	in;


        	endo 	=	y;
         	exog
				x_l1-x_l18
				month_indicator2-month_indicator192;

         	parms
				a
				b
				l
				t2-t192;



		mflow	 =
				a	+	
				b * (
                                        %do i = 1 %to 18;
                                          %let j = %eval(&amp;amp;i-1);
                                          exp(-l*(&amp;amp;j))*x_l&amp;amp;i. +
				        %end;

					%do i = 2 %to 191;
						t&amp;amp;i.*month_indicator&amp;amp;i. + 
					%end;
					t192*month_indicator192;

		 	fit mflow
				/ gmm;

		 	ods output
				ParameterEstimates	=	ParameterEstimates_sine_exp_x
				ResidSummary		=	ResidSummary_sine_exp_x;

run; quit;
%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And then call&amp;nbsp;%call_model;&lt;/P&gt;
&lt;P&gt;There are also some useful options when you use sas macro, especially useful for debugging:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;
options mlogic;
options symbolgen;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The MPRINT option&amp;nbsp;&lt;SPAN&gt;writes to the SAS log each SAS statement generated by a macro&lt;/SPAN&gt;.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The MLOGIC option traces the flow of execution of your macro, including the resolution of parameters.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The SYMBOLGEN option tells you what each macro variable resolves to by writing messages to the SAS log.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2017 14:12:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Abbreviation-of-long-sums-in-proc-model/m-p/392212#M2638</guid>
      <dc:creator>Puwang</dc:creator>
      <dc:date>2017-08-31T14:12:24Z</dc:date>
    </item>
    <item>
      <title>Re: Abbreviation of long sums in proc model</title>
      <link>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Abbreviation-of-long-sums-in-proc-model/m-p/392215#M2639</link>
      <description>&lt;P&gt;This comes in very handy, thank you very much.&lt;/P&gt;&lt;P&gt;Keeps it all tidied up and in one place in the 'proc model' statement.&lt;/P&gt;&lt;P&gt;I may use multiple 'tmp' as you dubbed them, with different lengths and then fit them together in the actual model equation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And thank you for elaborating on your answer and given even more hints on how I could improve further, Pu.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Astonishing, how quickly this request has been solved one again.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Aug 2017 14:19:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Forecasting-and-Econometrics/Abbreviation-of-long-sums-in-proc-model/m-p/392215#M2639</guid>
      <dc:creator>Sinistrum</dc:creator>
      <dc:date>2017-08-31T14:19:22Z</dc:date>
    </item>
  </channel>
</rss>

