<?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: Regression using a Macro in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Regression-using-a-Macro/m-p/870016#M38489</link>
    <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/441784"&gt;@Ata_Rabbi&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n0n5mm9l2pmpevn1lsjqccmgp8tx.htm#p09gb0or6nr4oyn1mc3gxyw6sqhe" target="_blank" rel="noopener"&gt;BY-group processing&lt;/A&gt;, not macro loops, to apply a procedure to observations which are grouped together and identified by the values of one or more variables.&lt;/P&gt;
&lt;PRE&gt;proc reg data=have noprint
outest= PE2(drop=_model_); /* save parameter estimates */
&lt;FONT size="3"&gt;&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;by permno;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;
model excess_ret = MKT_RF SMB HML RMW CMA;                          
quit;&lt;/PRE&gt;
&lt;P&gt;If dataset HAVE is not sorted, but only &lt;EM&gt;grouped&lt;/EM&gt; by PERMNO, add the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p0yeyftk8ftuckn1o5qzy53284gz.htm#p15nij2ef6sunen1o4m7dqh90re0" target="_blank" rel="noopener"&gt;NOTSORTED option&lt;/A&gt; to the BY statement:&lt;/P&gt;
&lt;PRE&gt;by permno &lt;STRONG&gt;notsorted&lt;/STRONG&gt;;&lt;/PRE&gt;</description>
    <pubDate>Sat, 15 Apr 2023 22:35:04 GMT</pubDate>
    <dc:creator>FreelanceReinh</dc:creator>
    <dc:date>2023-04-15T22:35:04Z</dc:date>
    <item>
      <title>Regression using a Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Regression-using-a-Macro/m-p/870014#M38488</link>
      <description>&lt;P&gt;Hello good people. I am very new to SAS. I have the following sample dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input Permno$ date : mmddyy10. excess_ret mkt_rf SMB HML RMW CMA;&lt;BR /&gt;format date mmddyy10.;&lt;BR /&gt;cards;&lt;BR /&gt;10375 03/22/04 -0.013158 -1.42 -0.6 -0.22 0.67 -0.7&lt;BR /&gt;10375 03/23/04 0.000108 -0.09 0.4 0.02 0.46 -0.19&lt;BR /&gt;10375 03/24/04 -0.011773 -0.27 -0.18 -0.12 -0.23 0.14&lt;BR /&gt;10375 03/25/04 0.010224 1.68 0.56 -0.19 -1.14 0.76&lt;BR /&gt;10375 03/26/04 -0.014569 0 0.36 0.36 -0.12 0.2&lt;BR /&gt;10375 03/29/04 0.028457 1.34 0.52 -0.22 -0.27 0.27&lt;BR /&gt;10375 03/30/04 -0.00022 0.47 0.49 0.15 -0.12 0.13&lt;BR /&gt;10375 03/31/04 0.008289 0 0.22 0.22 0.4 0.02&lt;BR /&gt;10375 04/01/04 -0.00165 0.64 0.19 0.04 -0.45 0.14&lt;BR /&gt;10397 03/22/04 0.00705 -1.42 -0.6 -0.22 0.67 -0.7&lt;BR /&gt;10397 03/23/04 0.007475 -0.09 0.4 0.02 0.46 -0.19&lt;BR /&gt;10397 03/24/04 0.014368 -0.27 -0.18 -0.12 -0.23 0.14&lt;BR /&gt;10397 03/25/04 0.025178 1.68 0.56 -0.19 -1.14 0.76&lt;BR /&gt;10397 03/26/04 0.002701 0 0.36 0.36 -0.12 0.2&lt;BR /&gt;10397 03/29/04 -0.012705 1.34 0.52 -0.22 -0.27 0.27&lt;BR /&gt;10397 03/30/04 -0.020012 0.47 0.49 0.15 -0.12 0.13&lt;BR /&gt;10397 03/31/04 -0.009249 0 0.22 0.22 0.4 0.02&lt;BR /&gt;10397 04/01/04 -0.001889 0.64 0.19 0.04 -0.45 0.14&lt;BR /&gt;11618 03/22/04 -0.008181 -1.42 -0.6 -0.22 0.67 -0.7&lt;BR /&gt;11618 03/23/04 -0.001691 -0.09 0.4 0.02 0.46 -0.19&lt;BR /&gt;11618 03/24/04 0.002283 -0.27 -0.18 -0.12 -0.23 0.14&lt;BR /&gt;11618 03/25/04 0.037623 1.68 0.56 -0.19 -1.14 0.76&lt;BR /&gt;11618 03/26/04 -0.008995 0 0.36 0.36 -0.12 0.2&lt;BR /&gt;11618 03/29/04 0.020096 1.34 0.52 -0.22 -0.27 0.27&lt;BR /&gt;11618 03/30/04 0.008157 0.47 0.49 0.15 -0.12 0.13&lt;BR /&gt;11618 03/31/04 0.036101 0 0.22 0.22 0.4 0.02&lt;BR /&gt;11618 04/01/04 -0.031007 0.64 0.19 0.04 -0.45 0.14&lt;/P&gt;&lt;P&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is a small subset of my dataset. As you can see, I have multiple Permno and each Permno has multiple and equal numbers of days of observation. I am trying to run a loop in which:&lt;/P&gt;&lt;P&gt;1) all observations for each Permno will be extracted.&lt;/P&gt;&lt;P&gt;2) Then I want to run a regression for extracted Permno observations and store the coefficients in a separate table.&lt;/P&gt;&lt;P&gt;3) Repeat this process for the next Permno and store the coefficients in the same table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently, I can extract rows and run a regression using the following codes:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data test2; 
set have;
where Permno = "11618";
run;
proc reg data=test2 noprint
            outest=&amp;nbsp;PE2; /* save parameter estimates */
   model excess_ret = MKT_RF SMB HML RMW CMA;                          &lt;BR /&gt;   quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;But I want to do this in a loop/macro because I have thousands of Permno.&lt;/P&gt;&lt;P&gt;The output for the sample dataset would look something like this:&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="ss sas.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/82739iA81A34F03DB633E7/image-size/large?v=v2&amp;amp;px=999" role="button" title="ss sas.png" alt="ss sas.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have made some edits to the output by myself; however, I would like it to look like the picture.&lt;/P&gt;&lt;P&gt;I truly appreciate your kindness and support as I am going through a tough time. Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 15 Apr 2023 21:37:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Regression-using-a-Macro/m-p/870014#M38488</guid>
      <dc:creator>Ata_Rabbi</dc:creator>
      <dc:date>2023-04-15T21:37:23Z</dc:date>
    </item>
    <item>
      <title>Re: Regression using a Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Regression-using-a-Macro/m-p/870016#M38489</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/441784"&gt;@Ata_Rabbi&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/proc/n0n5mm9l2pmpevn1lsjqccmgp8tx.htm#p09gb0or6nr4oyn1mc3gxyw6sqhe" target="_blank" rel="noopener"&gt;BY-group processing&lt;/A&gt;, not macro loops, to apply a procedure to observations which are grouped together and identified by the values of one or more variables.&lt;/P&gt;
&lt;PRE&gt;proc reg data=have noprint
outest= PE2(drop=_model_); /* save parameter estimates */
&lt;FONT size="3"&gt;&lt;STRONG&gt;&lt;FONT color="#3366FF"&gt;by permno;&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;
model excess_ret = MKT_RF SMB HML RMW CMA;                          
quit;&lt;/PRE&gt;
&lt;P&gt;If dataset HAVE is not sorted, but only &lt;EM&gt;grouped&lt;/EM&gt; by PERMNO, add the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p0yeyftk8ftuckn1o5qzy53284gz.htm#p15nij2ef6sunen1o4m7dqh90re0" target="_blank" rel="noopener"&gt;NOTSORTED option&lt;/A&gt; to the BY statement:&lt;/P&gt;
&lt;PRE&gt;by permno &lt;STRONG&gt;notsorted&lt;/STRONG&gt;;&lt;/PRE&gt;</description>
      <pubDate>Sat, 15 Apr 2023 22:35:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Regression-using-a-Macro/m-p/870016#M38489</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2023-04-15T22:35:04Z</dc:date>
    </item>
    <item>
      <title>Re: Regression using a Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Regression-using-a-Macro/m-p/870017#M38490</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;. It was so simple that I now feel silly. But thank you so much for figuring out for me. Truly appreciate your support and time.&lt;/P&gt;</description>
      <pubDate>Sat, 15 Apr 2023 23:31:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Regression-using-a-Macro/m-p/870017#M38490</guid>
      <dc:creator>Ata_Rabbi</dc:creator>
      <dc:date>2023-04-15T23:31:53Z</dc:date>
    </item>
    <item>
      <title>Re: Regression using a Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Regression-using-a-Macro/m-p/870029#M38491</link>
      <description>&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/441784"&gt;@Ata_Rabbi&lt;/a&gt; it is not correct in this case to mark your answer correct, as you did not provide an answer. You need to mark the answer from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt; as correct, because it is the correct answer.&lt;/P&gt;</description>
      <pubDate>Sun, 16 Apr 2023 10:09:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Regression-using-a-Macro/m-p/870029#M38491</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-16T10:09:37Z</dc:date>
    </item>
    <item>
      <title>Re: Regression using a Macro</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Regression-using-a-Macro/m-p/870071#M38494</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;for pointing that out. I have corrected the error and accepted&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;'s answer as the solution. Please excuse my mistake as I am new to this forum.&lt;/P&gt;</description>
      <pubDate>Sun, 16 Apr 2023 18:26:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Regression-using-a-Macro/m-p/870071#M38494</guid>
      <dc:creator>Ata_Rabbi</dc:creator>
      <dc:date>2023-04-16T18:26:01Z</dc:date>
    </item>
  </channel>
</rss>

