<?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: running thousands of regression in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/running-thousands-of-regression/m-p/454011#M114759</link>
    <description>&lt;P&gt;Now that I read the OP's question more carefully, I think this is&amp;nbsp;simple to&amp;nbsp;implement if the data does not have many missing values. The OP has&amp;nbsp;multiple response variables. You just need to create the differences (Y[i] - RF) and then put all the difference variables on the left side of the equal sign on the MODEL statement. There is no need to transpose the data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;   /* simulate data */
call streaminit(1);
array y[3];
array x[4];
do i = 1 to 100;
   do j = 1 to dim(x);
      x[j] = rand("Normal");
   end;
   do j = 1 to dim(y);
      y[j] = -1 + 2*x[1] - 3*x[2] + 4*x[3] + rand("Normal");
   end;
   output;
end;


%let p = 3;   /* &amp;lt;== make this 2000 if the variables are Y1-Y2000 */
data Diff / view=Diff;  /* create view for the differences */
set Have;
array y[*] y1-y&amp;amp;p;
array Diff[*] Diff1-Diff&amp;amp;p;
do i = 1 to dim(y);
   Diff[i] = y[i] - X1;
end;
run;

proc reg data=Diff noprint outest=PE;
   model Diff1-Diff&amp;amp;p = x1-x4;  /* all responses on left-hand side */
run;

proc print data=PE;
   var _DEPVAR_ Intercept;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 13 Apr 2018 18:05:30 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2018-04-13T18:05:30Z</dc:date>
    <item>
      <title>running thousands of regression</title>
      <link>https://communities.sas.com/t5/SAS-Programming/running-thousands-of-regression/m-p/453418#M114575</link>
      <description>&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t;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;and so on&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;I want to run a regression in the following form;&lt;/P&gt;&lt;P&gt;&amp;nbsp;(Yi – RF) = α + Mkt-RF +&amp;nbsp;&amp;nbsp; SMB + HML&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where i=1 to 2000&lt;/P&gt;&lt;P&gt;This essentially means that I want 2000 different regressions as my dependent variable is changing everytime.&lt;/P&gt;&lt;P&gt;Also my data only contains Yi, and I have to compute Yi-RF for each regression and finally I want one summary file that extracts the intercept term of each regression.&lt;/P&gt;&lt;P&gt;I am unsure on how to go about it. I can run individual regressions in SAS but generating thousands of regressions of this sort, I am not getting how to do it. Can anyone help me on this?&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 00:34:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/running-thousands-of-regression/m-p/453418#M114575</guid>
      <dc:creator>Amalik</dc:creator>
      <dc:date>2018-04-12T00:34:11Z</dc:date>
    </item>
    <item>
      <title>Re: running thousands of regression</title>
      <link>https://communities.sas.com/t5/SAS-Programming/running-thousands-of-regression/m-p/453458#M114585</link>
      <description>&lt;P&gt;Transpose to a long format and use by?&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 06:45:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/running-thousands-of-regression/m-p/453458#M114585</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-12T06:45:13Z</dc:date>
    </item>
    <item>
      <title>Re: running thousands of regression</title>
      <link>https://communities.sas.com/t5/SAS-Programming/running-thousands-of-regression/m-p/453525#M114607</link>
      <description>&lt;P&gt;&lt;A href="https://blogs.sas.com/content/iml/2017/02/13/run-1000-regressions.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2017/02/13/run-1000-regressions.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 12:46:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/running-thousands-of-regression/m-p/453525#M114607</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-04-12T12:46:51Z</dc:date>
    </item>
    <item>
      <title>Re: running thousands of regression</title>
      <link>https://communities.sas.com/t5/SAS-Programming/running-thousands-of-regression/m-p/453531#M114610</link>
      <description>&lt;P&gt;I always point out:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just because you CAN run 1000s of regressions doesn't mean you SHOULD run 1000s of regressions.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's not clear why you want to do this, but usually there are better methods to accomplish your goals than brute force running 1000s of regressions.&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 12:59:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/running-thousands-of-regression/m-p/453531#M114610</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-04-12T12:59:56Z</dc:date>
    </item>
    <item>
      <title>Re: running thousands of regression</title>
      <link>https://communities.sas.com/t5/SAS-Programming/running-thousands-of-regression/m-p/453778#M114696</link>
      <description>&lt;P&gt;Hi Miler,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to run this regression because I want to extract intercept term of each regression to be used as input for another data set. Do you have an easier suggestion?&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;</description>
      <pubDate>Thu, 12 Apr 2018 22:28:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/running-thousands-of-regression/m-p/453778#M114696</guid>
      <dc:creator>Amalik</dc:creator>
      <dc:date>2018-04-12T22:28:24Z</dc:date>
    </item>
    <item>
      <title>Re: running thousands of regression</title>
      <link>https://communities.sas.com/t5/SAS-Programming/running-thousands-of-regression/m-p/453779#M114697</link>
      <description>&lt;P&gt;Hi Miler,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to use intercept term of each regression to be used as input for another data set. Do you have another suggestion?&lt;/P&gt;</description>
      <pubDate>Thu, 12 Apr 2018 22:29:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/running-thousands-of-regression/m-p/453779#M114697</guid>
      <dc:creator>Amalik</dc:creator>
      <dc:date>2018-04-12T22:29:26Z</dc:date>
    </item>
    <item>
      <title>Re: running thousands of regression</title>
      <link>https://communities.sas.com/t5/SAS-Programming/running-thousands-of-regression/m-p/453836#M114725</link>
      <description>&lt;P&gt;See this simple example code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input var1 $ var2 $ y1 y2 y3;
cards;
x y 1 2 3
a b 4 5 6
;
run;

proc transpose data=have out=int (rename=(col1=y));
by var1 var2 notsorted;
var y:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can now sort dataset int by _name_ and use _name_ in a by statement in your regression analysis.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 05:54:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/running-thousands-of-regression/m-p/453836#M114725</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-04-13T05:54:52Z</dc:date>
    </item>
    <item>
      <title>Re: running thousands of regression</title>
      <link>https://communities.sas.com/t5/SAS-Programming/running-thousands-of-regression/m-p/453918#M114745</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/114858"&gt;@Amalik&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi Miller,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to use intercept term of each regression to be used as input for another data set. Do you have another suggestion?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Given the very limited explanation ("used as input for another data set" and then how is it used?), there's no way I can give any useful suggestions.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In fact, you seem to be implying that you have Y1-Y2000 (that's two thousand Y variables), is that right? They're not independent of one another, they are correlated, perhaps some method that takes into account the correlation would help.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 14:14:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/running-thousands-of-regression/m-p/453918#M114745</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-04-13T14:14:29Z</dc:date>
    </item>
    <item>
      <title>Re: running thousands of regression</title>
      <link>https://communities.sas.com/t5/SAS-Programming/running-thousands-of-regression/m-p/453946#M114750</link>
      <description>&lt;P&gt;If you need to use PROC REG,&amp;nbsp;use KSharp's suggestion and read that blog post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, if you only want the intercepts, not the other parameter estimates, you don't need to use PROC REG or even transpose the data. If you have SAS/IML, you can obtain the intercept estimates from the matrix of crossproducts&amp;nbsp;by applying a SWEEP operator to the explanatory variables (plus intercept column). The intercept estimates are then in the first row of the swept&amp;nbsp;matrix:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
call streaminit(1);
array y[5];
array diff[5];
do time = 1 to 100;
   RF  = rand("Normal");
   Mkt = rand("Normal");
   SMB = rand("Normal");
   HML = rand("Normal");
   MktRF = Mkt - RF;
   do i = 1 to dim(y);
      y[i] = rand("Normal");
      diff[i] = Y[i] - RF;
   end;
   output;
end;

ods exclude all;
proc reg data=A plots=none;
var Y1-Y5 Diff1-Diff5 MktRF SMB HML;
Diff1: model Diff1 = MktRF SMB HML;
Diff2: model Diff2 = MktRF SMB HML;
Diff3: model Diff3 = MktRF SMB HML;
Diff4: model Diff4 = MktRF SMB HML;
Diff5: model Diff5 = MktRF SMB HML;
ods output ParameterEstimates=PE;
run;
ods exclude none;

/* print just the intercept estimates */
proc print data=PE(where=(Variable="Intercept"));run;

proc iml;
XNames = {MktRF SMB HML};
YNames = "Diff1":"Diff5";
varNames = XNames || YNames;
use A; read all var varNames into X; close;

/* add intercept column */
XNames = "Intercept" || XNames;
varNames = XNames || YNames;
X = j(nrow(X), 1, 1) || X;

/* for crossproducts and sweep the explanatory columns */
XpX = X`*X;
S = sweep(XpX, 1:ncol(XNames));
/* 1st row contains intercepts; get column names for Y variables */
InterceptOnly = S[1, ncol(XNames)+1: ncol(varNames)]; 
print InterceptOnly[c=YNames];&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Apr 2018 15:08:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/running-thousands-of-regression/m-p/453946#M114750</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-04-13T15:08:49Z</dc:date>
    </item>
    <item>
      <title>Re: running thousands of regression</title>
      <link>https://communities.sas.com/t5/SAS-Programming/running-thousands-of-regression/m-p/454011#M114759</link>
      <description>&lt;P&gt;Now that I read the OP's question more carefully, I think this is&amp;nbsp;simple to&amp;nbsp;implement if the data does not have many missing values. The OP has&amp;nbsp;multiple response variables. You just need to create the differences (Y[i] - RF) and then put all the difference variables on the left side of the equal sign on the MODEL statement. There is no need to transpose the data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Have;   /* simulate data */
call streaminit(1);
array y[3];
array x[4];
do i = 1 to 100;
   do j = 1 to dim(x);
      x[j] = rand("Normal");
   end;
   do j = 1 to dim(y);
      y[j] = -1 + 2*x[1] - 3*x[2] + 4*x[3] + rand("Normal");
   end;
   output;
end;


%let p = 3;   /* &amp;lt;== make this 2000 if the variables are Y1-Y2000 */
data Diff / view=Diff;  /* create view for the differences */
set Have;
array y[*] y1-y&amp;amp;p;
array Diff[*] Diff1-Diff&amp;amp;p;
do i = 1 to dim(y);
   Diff[i] = y[i] - X1;
end;
run;

proc reg data=Diff noprint outest=PE;
   model Diff1-Diff&amp;amp;p = x1-x4;  /* all responses on left-hand side */
run;

proc print data=PE;
   var _DEPVAR_ Intercept;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Apr 2018 18:05:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/running-thousands-of-regression/m-p/454011#M114759</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-04-13T18:05:30Z</dc:date>
    </item>
  </channel>
</rss>

