<?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: Maximum value for each firm in a month based on daily returns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Maximum-value-for-each-firm-in-a-month-based-on-daily-returns/m-p/336159#M76187</link>
    <description>I guess it might be because of error in date format, I just noticed it now. I will try to fix it.</description>
    <pubDate>Mon, 27 Feb 2017 11:34:09 GMT</pubDate>
    <dc:creator>MAC1430</dc:creator>
    <dc:date>2017-02-27T11:34:09Z</dc:date>
    <item>
      <title>Maximum value for each firm in a month based on daily returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Maximum-value-for-each-firm-in-a-month-based-on-daily-returns/m-p/336094#M76162</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;At the end of each month t, I want to get the value of&amp;nbsp;maximum&amp;nbsp;return for each stock based on its daily returns from month t. There will be almost 20-25 daily observations in a month, but I am keeping very few in the sample for the convenience. Furthermore, I also want to get the average of two, three, four and five maximum values in a month for each stock too &amp;nbsp;(I put few daily observations; therefore, I understand that the average of four and five maximum returns might not be possible, but I just need the code).&lt;/P&gt;
&lt;P&gt;The&amp;nbsp;original data is around 30 million observations. Please find the SAS data below. Based on this data, I estimate the maximum return on for stock ID 1 for 201001 (January 2010), and it should be&amp;nbsp;&lt;SPAN style="background-color: #f3f3f3; color: #333333; font-family: HelevticaNeue-light, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px;"&gt;0.04135&lt;/SPAN&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks a lot for your help.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Best,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheema&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs truncover;
input stock date : yymmdd8. ret ;
format date yymmdd8.;
cards;
1 20100107 0.04135
1 20100126 -0.02544
1 20100129 0.03384
1 20100201 0.01089
1 20100202 0.02621
1 20100226 0.01001
1 20100301 -0.0132
1 20100330 -0.0181
1 20100331 -0.00308
1 20100401 0.05394
1 20100429 -0.01077
1 20100430 0.0031
1 20100503 0.00931
1 20100521 0
1 20100531 -0.01427
1 20100601 -0.02718
1 20100617 0.05019
1 20100630 -0.01236
1 20100701 0
1 20100728 0.01193
1 20100730 0.01621
1 20100802 -0.0174
2 20100107 0.06069
2 20100126 -0.06219
2 20100129 0.01989
2 20100201 -0.04551
2 20100202 0.04768
2 20100226 -0.05462
2 20100301 0.02613
2 20100330 -0.04155
2 20100331 0.04336
2 20100401 -0.00536
2 20100429 -0.02561
2 20100430 -0.0166
2 20100503 0.00563
2 20100521 0
2 20100531 0.01119
2 20100601 0
2 20100617 0.01521
2 20100630 0.27384
2 20100701 0.09519
2 20100728 -0.12793
2 20100730 -0.04815
2 20100802 -0.02235
run
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;Cheema&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Feb 2017 04:20:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Maximum-value-for-each-firm-in-a-month-based-on-daily-returns/m-p/336094#M76162</guid>
      <dc:creator>MAC1430</dc:creator>
      <dc:date>2017-02-27T04:20:48Z</dc:date>
    </item>
    <item>
      <title>Re: Maximum value for each firm in a month based on daily returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Maximum-value-for-each-firm-in-a-month-based-on-daily-returns/m-p/336098#M76163</link>
      <description>&lt;P&gt;So do you wish to output three observations&amp;nbsp;&lt;SPAN&gt;for stock ID 1 for 201001 (January 2010) and only have the maximum value at the last observation in that month or only one observation per month? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Feb 2017 06:32:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Maximum-value-for-each-firm-in-a-month-based-on-daily-returns/m-p/336098#M76163</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-02-27T06:32:41Z</dc:date>
    </item>
    <item>
      <title>Re: Maximum value for each firm in a month based on daily returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Maximum-value-for-each-firm-in-a-month-based-on-daily-returns/m-p/336099#M76164</link>
      <description>&lt;P&gt;Thanks, only one observation per month for each stock.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Feb 2017 06:34:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Maximum-value-for-each-firm-in-a-month-based-on-daily-returns/m-p/336099#M76164</guid>
      <dc:creator>MAC1430</dc:creator>
      <dc:date>2017-02-27T06:34:54Z</dc:date>
    </item>
    <item>
      <title>Re: Maximum value for each firm in a month based on daily returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Maximum-value-for-each-firm-in-a-month-based-on-daily-returns/m-p/336150#M76182</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs truncover;
input stock date : yymmdd8. ret ;
format date yymmdd8.;
cards;
1 20100107 0.04135
1 20100126 -0.02544
1 20100129 0.03384
1 20100201 0.01089
1 20100202 0.02621
1 20100226 0.01001
1 20100301 -0.0132
1 20100330 -0.0181
1 20100331 -0.00308
1 20100401 0.05394
1 20100429 -0.01077
1 20100430 0.0031
1 20100503 0.00931
1 20100521 0
1 20100531 -0.01427
1 20100601 -0.02718
1 20100617 0.05019
1 20100630 -0.01236
1 20100701 0
1 20100728 0.01193
1 20100730 0.01621
1 20100802 -0.0174
2 20100107 0.06069
2 20100126 -0.06219
2 20100129 0.01989
2 20100201 -0.04551
2 20100202 0.04768
2 20100226 -0.05462
2 20100301 0.02613
2 20100330 -0.04155
2 20100331 0.04336
2 20100401 -0.00536
2 20100429 -0.02561
2 20100430 -0.0166
2 20100503 0.00563
2 20100521 0
2 20100531 0.01119
2 20100601 0
2 20100617 0.01521
2 20100630 0.27384
2 20100701 0.09519
2 20100728 -0.12793
2 20100730 -0.04815
2 20100802 -0.02235
;
run;
proc summary data=have;
by stock date;
format date monyy.;
var ret;
output out=want max=ret_max;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 27 Feb 2017 10:51:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Maximum-value-for-each-firm-in-a-month-based-on-daily-returns/m-p/336150#M76182</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-02-27T10:51:58Z</dc:date>
    </item>
    <item>
      <title>Re: Maximum value for each firm in a month based on daily returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Maximum-value-for-each-firm-in-a-month-based-on-daily-returns/m-p/336152#M76184</link>
      <description>&lt;P&gt;Thanks Ksharp. It will be great if you can please help me with the second part where I want to get the average of two, three, four and five maximum values in a month for each stock too &amp;nbsp;(I put few daily observations; therefore, I understand that the average of four and five maximum returns might not be possible based on the provided dataset, but please make it for the average of three returns in a month and I will edit the code then).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Feb 2017 11:05:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Maximum-value-for-each-firm-in-a-month-based-on-daily-returns/m-p/336152#M76184</guid>
      <dc:creator>MAC1430</dc:creator>
      <dc:date>2017-02-27T11:05:24Z</dc:date>
    </item>
    <item>
      <title>Re: Maximum value for each firm in a month based on daily returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Maximum-value-for-each-firm-in-a-month-based-on-daily-returns/m-p/336155#M76185</link>
      <description>&lt;P&gt;1) sort the dataset by descending order&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;year=(date);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;month=month(date);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc sort data=have;&lt;/P&gt;
&lt;P&gt;by id year month &amp;nbsp;descending ret;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) pick up the most large five obs for each id,after that do PROC SUMMAYR just as I did.&lt;/P&gt;
&lt;P&gt;data top_five;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;by id year month;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;if first.month then n=0;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;n+1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;if n le 5;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Feb 2017 11:17:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Maximum-value-for-each-firm-in-a-month-based-on-daily-returns/m-p/336155#M76185</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-02-27T11:17:38Z</dc:date>
    </item>
    <item>
      <title>Re: Maximum value for each firm in a month based on daily returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Maximum-value-for-each-firm-in-a-month-based-on-daily-returns/m-p/336157#M76186</link>
      <description>Hi Ksharp, thanks for it. There is just one problem that n remains 1, I guess it might be an error in first.month. Can you please kindly check it?</description>
      <pubDate>Mon, 27 Feb 2017 11:30:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Maximum-value-for-each-firm-in-a-month-based-on-daily-returns/m-p/336157#M76186</guid>
      <dc:creator>MAC1430</dc:creator>
      <dc:date>2017-02-27T11:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: Maximum value for each firm in a month based on daily returns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Maximum-value-for-each-firm-in-a-month-based-on-daily-returns/m-p/336159#M76187</link>
      <description>I guess it might be because of error in date format, I just noticed it now. I will try to fix it.</description>
      <pubDate>Mon, 27 Feb 2017 11:34:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Maximum-value-for-each-firm-in-a-month-based-on-daily-returns/m-p/336159#M76187</guid>
      <dc:creator>MAC1430</dc:creator>
      <dc:date>2017-02-27T11:34:09Z</dc:date>
    </item>
  </channel>
</rss>

