<?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: 1 year (252 days) Buy and hold abnormal return for daily data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853821#M337459</link>
    <description>&lt;P&gt;I do not have missing values. I already delete them.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 13 Jan 2023 21:41:44 GMT</pubDate>
    <dc:creator>Fer_</dc:creator>
    <dc:date>2023-01-13T21:41:44Z</dc:date>
    <item>
      <title>1 year (252 days) Buy and hold abnormal return for daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853594#M337398</link>
      <description>&lt;P&gt;Hello everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to calculate buy and hold abnormal return for 252 days for daily dataset for different firms (identify by cusip), I provide my dataset bellow.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;BHAR(1)&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;=&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;{&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;[(1+ret) of day1] *&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;[(1+ret) of day2] *&amp;nbsp;[(1+ret) of day 3] *&amp;nbsp;[(1+ret) of day4] *&amp;nbsp; ... *&amp;nbsp;[(1+ret) of day 252]&amp;nbsp;&lt;STRONG&gt;}&lt;/STRONG&gt;&amp;nbsp;&lt;FONT size="5"&gt;&lt;STRONG&gt;-&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp;&lt;STRONG&gt;{&lt;/STRONG&gt;&amp;nbsp;[(1+vwretd) of day1] *&amp;nbsp;[(1+vwretd) of day2] *&amp;nbsp;[(1+vwretd) of day3] *&amp;nbsp;[(1+vwretd) of day4] *&amp;nbsp; ... *&amp;nbsp;[(1+vwretd) of day252&amp;nbsp;&lt;STRONG&gt;}&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I really appreciate your help.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks in advance&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="photo1.png" style="width: 424px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/79332i60207BD18B1FC01C/image-dimensions/424x476?v=v2" width="424" height="476" role="button" title="photo1.png" alt="photo1.png" /&gt;&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Jan 2023 23:40:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853594#M337398</guid>
      <dc:creator>Fer_</dc:creator>
      <dc:date>2023-01-12T23:40:36Z</dc:date>
    </item>
    <item>
      <title>Re: 1 year (252 days) Buy and hold abnormal return for daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853596#M337399</link>
      <description>Please provide sample data as text or ideally as a data step, not as an image. I'm assuming you have a large data set?&lt;BR /&gt;Output is one number per CUSIP per year? Resets every year or is cumulative? Is your data guaranteed to have the correct data intervals or could you have missing data that needs to be accounted for?</description>
      <pubDate>Thu, 12 Jan 2023 23:50:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853596#M337399</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-01-12T23:50:53Z</dc:date>
    </item>
    <item>
      <title>Re: 1 year (252 days) Buy and hold abnormal return for daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853600#M337400</link>
      <description>&lt;P&gt;Thanks for your reply.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yes I have a large dataset. I provide a sample bellow as text. For every year in my sample, I have stock return and market return without missing data.( I already delete them)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;cusip&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;year&lt;/TD&gt;&lt;TD&gt;ret&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;vwretd&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11001&lt;/TD&gt;&lt;TD&gt;19900123&lt;/TD&gt;&lt;TD&gt;-0.055&lt;/TD&gt;&lt;TD&gt;-0.002&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11001&lt;/TD&gt;&lt;TD&gt;19900124&lt;/TD&gt;&lt;TD&gt;-0.0098&lt;/TD&gt;&lt;TD&gt;-0.006&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11001&lt;/TD&gt;&lt;TD&gt;19900125&lt;/TD&gt;&lt;TD&gt;-0.009&lt;/TD&gt;&lt;TD&gt;-0.013&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11001&lt;/TD&gt;&lt;TD&gt;19900128&lt;/TD&gt;&lt;TD&gt;-0.0087&lt;/TD&gt;&lt;TD&gt;-0.007&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;..&lt;/TD&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11001&lt;/TD&gt;&lt;TD&gt;20211231&lt;/TD&gt;&lt;TD&gt;0.003&lt;/TD&gt;&lt;TD&gt;0.0056&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11002&lt;/TD&gt;&lt;TD&gt;19900204&lt;/TD&gt;&lt;TD&gt;-0.0019&lt;/TD&gt;&lt;TD&gt;-0.004&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11002&lt;/TD&gt;&lt;TD&gt;19900205&lt;/TD&gt;&lt;TD&gt;-0.014&lt;/TD&gt;&lt;TD&gt;-0.0045&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11002&lt;/TD&gt;&lt;TD&gt;20211231&lt;/TD&gt;&lt;TD&gt;0.004&lt;/TD&gt;&lt;TD&gt;-0.007&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11003&lt;/TD&gt;&lt;TD&gt;19900115&lt;/TD&gt;&lt;TD&gt;0.0013&lt;/TD&gt;&lt;TD&gt;0.0016&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11003&lt;/TD&gt;&lt;TD&gt;19900116&lt;/TD&gt;&lt;TD&gt;-0.014&lt;/TD&gt;&lt;TD&gt;0.001&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;TD&gt;…&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11003&lt;/TD&gt;&lt;TD&gt;20211231&lt;/TD&gt;&lt;TD&gt;0.005&lt;/TD&gt;&lt;TD&gt;-0.007&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 13 Jan 2023 00:00:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853600#M337400</guid>
      <dc:creator>Fer_</dc:creator>
      <dc:date>2023-01-13T00:00:35Z</dc:date>
    </item>
    <item>
      <title>Re: 1 year (252 days) Buy and hold abnormal return for daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853609#M337402</link>
      <description>&lt;OL&gt;
&lt;LI&gt;Do you want rolling 252-day returns?&lt;/LI&gt;
&lt;LI&gt;Do you want only full 252-day windows?&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Let's say your answer to each question is yes.&amp;nbsp; Then: (code amended):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_:);
  set have;
  by cusip notsorted;

  if first.cusip then call missing(_obs,_sum_log_cusip_ret_plus1,_sum_log_index_ret_plus1);
  _obs+1;
  
  _sum_log_cusip_ret_plus1 + log(1+ret)    - ifn(_obs&amp;gt;252,lag252(log(1+ret)),0) ;

  _sum_log_index_ret_plus1 + log(1+vwretd) - ifn(_obs&amp;gt;252,lag252(log(1+vwretd)),0);

  window_start = lag251(year) ;

  if _obs&amp;gt;=252 ;
  bhar_252 =  exp(_sum_log_cusip_ret_plus1) - exp(_sum_log_index_ret_plus1) ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This assumes your data are sorted by cusip and date (which you have labelled as year).&amp;nbsp; Now if the data are not sorted by cusip, but are sorted by date within cusip, you can change&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  by cusip;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;to&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  by cusip notsorted;&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;Now note that this involves calculating 252-day cumulative returns for VWRETD for each CUSIP.&amp;nbsp; But the VWRETD is based on a market index, and thus has the same value for every cusip on each given date.&amp;nbsp; This means that if you have, say, 400 CUSIPs, you will be calculating the same values 400 times for the VWRETD components, where you really need to do it only once.&amp;nbsp; After calculating those returns once, you can store them in an array indexed by date.&amp;nbsp; Then, for each CUSIP, just retrieve them for calculating BHAR by date.&amp;nbsp; In other words, you could cut down your total calculations by half (400 times for 400 CUSIP returns, but only once for index returns).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Edited note&lt;/STRONG&gt;:&amp;nbsp; I didn't notice a missing close paren in the&amp;nbsp;lag252 argument.&amp;nbsp; It should have been&amp;nbsp;&lt;STRONG&gt;lag252(log(1+ret))&lt;/STRONG&gt;, not &lt;STRONG&gt;lag252(log(1+ret)&lt;/STRONG&gt;.&amp;nbsp; Same with the vwretd-based component.&amp;nbsp; It's now corrected in the code above.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also I have added retrieval of a window starting date, as per other comments by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/438372"&gt;@Fer_&lt;/a&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 18:40:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853609#M337402</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-01-13T18:40:19Z</dc:date>
    </item>
    <item>
      <title>Re: 1 year (252 days) Buy and hold abnormal return for daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853610#M337403</link>
      <description>&lt;P&gt;Thanks for your response.&lt;/P&gt;&lt;P&gt;I got these two errors:&lt;/P&gt;&lt;P&gt;ERROR 72-185: The LAG function call has too many arguments.&lt;/P&gt;&lt;P&gt;ERROR 71-185: The IFN function call does not have enough arguments.&lt;/P&gt;&lt;P&gt;for these lines of code:&lt;/P&gt;&lt;P&gt;sum_log_cusip_ret_plus1 + log(1+ret)- ifn(_obs&amp;gt;252,lag252(log(1+ret),0));&lt;BR /&gt;_sum_log_index_ret_plus1 + log(1+vwretd) - ifn(_obs&amp;gt;252,lag252(log(1+vwretd),0));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you know how to solve them? Thanks in advance.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 03:42:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853610#M337403</guid>
      <dc:creator>Fer_</dc:creator>
      <dc:date>2023-01-13T03:42:06Z</dc:date>
    </item>
    <item>
      <title>Re: 1 year (252 days) Buy and hold abnormal return for daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853611#M337404</link>
      <description>&lt;P&gt;And yes I want the rolling 252-days, which means that for each date and each cusip, I want to calculate bhar for that date and 251 days after that. For example for day1, I need bhar from day1 to day 252, then day 2 to day 253, day 3 to day 254...... until then end for each cusip.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 03:55:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853611#M337404</guid>
      <dc:creator>Fer_</dc:creator>
      <dc:date>2023-01-13T03:55:00Z</dc:date>
    </item>
    <item>
      <title>Re: 1 year (252 days) Buy and hold abnormal return for daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853755#M337428</link>
      <description>The 252 days - it doesn't matter if they're in a 'row' or should it be 252 days and ignore that there are missing values?</description>
      <pubDate>Fri, 13 Jan 2023 16:30:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853755#M337428</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-01-13T16:30:52Z</dc:date>
    </item>
    <item>
      <title>Re: 1 year (252 days) Buy and hold abnormal return for daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853781#M337443</link>
      <description>&lt;P&gt;This is why it's helpful to offer sample data in the form of a working data step.&amp;nbsp; I usually test against sample data.&amp;nbsp; In any case, this appears to be the result of a forgotten close paren, which I've changed in my initial response.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 18:43:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853781#M337443</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-01-13T18:43:20Z</dc:date>
    </item>
    <item>
      <title>Re: 1 year (252 days) Buy and hold abnormal return for daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853783#M337445</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/438372"&gt;@Fer_&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;And yes I want the rolling 252-days, which means that for each date and each cusip, I want to calculate bhar for that date and 251 days after that. For example for day1, I need bhar from day1 to day 252, then day 2 to day 253, day 3 to day 254...... until then end for each cusip.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;My previous code used the end-of-window date, but I've added code to provide beginning of window date.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 18:44:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853783#M337445</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-01-13T18:44:12Z</dc:date>
    </item>
    <item>
      <title>Re: 1 year (252 days) Buy and hold abnormal return for daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853807#M337452</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;your code does a 252 observation rolling calculation. If you're missing 6 months of data in there for some reason it will use part of one year and part of the other? (6 months isn't realistic but the trading days do vary by CUSPID IIRC).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 20:06:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853807#M337452</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-01-13T20:06:06Z</dc:date>
    </item>
    <item>
      <title>Re: 1 year (252 days) Buy and hold abnormal return for daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853820#M337458</link>
      <description>&lt;P&gt;Thanks for the code, unfortunately as my dataset is too large, I just could provide a small sample of it. I have a question about the code. My dataset starts from 1990 to 2021, but by running the code the window start is from 1991, which means that for every date the code notice to 252 days before that date. but I want to see 252 days ahead of each date. BHAR for day1= (1+ret day1)(1+ret of day2)....(1+ret day252)- ((1+vwretd day1)(1+vwretd day2)...(1+vwretd day252)).&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am thankful for your help.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 21:40:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853820#M337458</guid>
      <dc:creator>Fer_</dc:creator>
      <dc:date>2023-01-13T21:40:23Z</dc:date>
    </item>
    <item>
      <title>Re: 1 year (252 days) Buy and hold abnormal return for daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853821#M337459</link>
      <description>&lt;P&gt;I do not have missing values. I already delete them.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 21:41:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853821#M337459</guid>
      <dc:creator>Fer_</dc:creator>
      <dc:date>2023-01-13T21:41:44Z</dc:date>
    </item>
    <item>
      <title>Re: 1 year (252 days) Buy and hold abnormal return for daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853828#M337464</link>
      <description>So you have a 252 day sequence that's always in order with no daily gaps? My mistake, I interpreted your comment as you deleted the observations with missing data and thus had gaps in your time series, ie your dates could jump if data was missing.</description>
      <pubDate>Fri, 13 Jan 2023 23:14:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853828#M337464</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-01-13T23:14:52Z</dc:date>
    </item>
    <item>
      <title>Re: 1 year (252 days) Buy and hold abnormal return for daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853830#M337465</link>
      <description>&lt;P&gt;yes&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Jan 2023 23:16:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853830#M337465</guid>
      <dc:creator>Fer_</dc:creator>
      <dc:date>2023-01-13T23:16:52Z</dc:date>
    </item>
    <item>
      <title>Re: 1 year (252 days) Buy and hold abnormal return for daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853835#M337468</link>
      <description>Glad to hear. I probably wouldn't refer to that as 'I delete them' for your missing data. You've accounted for missing intervals in some manner instead (interpolation, spline etc), which is ideal. Good luck with your analysis!</description>
      <pubDate>Fri, 13 Jan 2023 23:37:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853835#M337468</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-01-13T23:37:11Z</dc:date>
    </item>
    <item>
      <title>Re: 1 year (252 days) Buy and hold abnormal return for daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853877#M337487</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/438372"&gt;@Fer_&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for the code, unfortunately as my dataset is too large, I just could provide a small sample of it. I have a question about the code. My dataset starts from 1990 to 2021, but by running the code the window start is from 1991, which means that for every date the code notice to 252 days before that date. but I want to see 252 days ahead of each date. BHAR for day1= (1+ret day1)(1+ret of day2)....(1+ret day252)- ((1+vwretd day1)(1+vwretd day2)...(1+vwretd day252)).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am thankful for your help.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you take a look at the code, as revised, you will see that I provided a WINDOWS_START date, so the BHAR values are look-ahead values.&amp;nbsp; So, examine the WINDOWS_START value, instead of the YEAR value (which will indicate the end of the window).&lt;/P&gt;</description>
      <pubDate>Sat, 14 Jan 2023 15:08:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853877#M337487</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-01-14T15:08:07Z</dc:date>
    </item>
    <item>
      <title>Re: 1 year (252 days) Buy and hold abnormal return for daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853883#M337490</link>
      <description>&lt;P&gt;Thanks for reply, for example for data in 1991, window start is 1990 and year 1991. And my dataset start from 1991 not 1990 by running the code. It seems to me that for 1991, the code starts to see lag 252 days before the date which means that the window start is 1990 (it sees the lag of 1991 not ahead).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Jan 2023 20:33:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853883#M337490</guid>
      <dc:creator>Fer_</dc:creator>
      <dc:date>2023-01-14T20:33:20Z</dc:date>
    </item>
    <item>
      <title>Re: 1 year (252 days) Buy and hold abnormal return for daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853887#M337493</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/438372"&gt;@Fer_&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for reply, for example for data in 1991, window start is 1990 and year 1991. And my dataset start from 1991 not 1990 by running the code. It seems to me that for 1991, the code starts to see lag 252 days before the date which means that the window start is 1990 (it sees the lag of 1991 not ahead).&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The solution&amp;nbsp;provided is really smart and efficient coding. It took me a bit to fully appreciate it and I was grateful to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;that he kept the code to the relevant minimum and didn't overload it with additional logic like some look-ahead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you spend the time to fully appreciate what has been given to you then you'll also see variable window_start. If you want to add the aggregated values at the beginning of your window then just use this variable to merge/join the values from Want to your Have table (on have.cusip=want.cusip and have.year=want.window_start).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1673742189032.png" style="width: 671px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/79408iCC63C6C5817B7536/image-dimensions/671x46?v=v2" width="671" height="46" role="button" title="Patrick_0-1673742189032.png" alt="Patrick_0-1673742189032.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Sample data can be mock-up data. It just needs to be representative of your real data. &lt;BR /&gt;Some code like below would suffice to create such sample data. If there could be some missing dates in your time series or similar then that's what you would have to mock-up as well for the sample to be representative.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  do cusip='11001','11999';
    do year='01jun2020'd to '20feb2021'd;
      ret=rand('uniform',-0.09,0.09);
      vwretd=rand('uniform',-0.09,0.09);
      output;
    end;
  end;
  format year yymmddn8.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jan 2023 00:29:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853887#M337493</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-01-15T00:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: 1 year (252 days) Buy and hold abnormal return for daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853890#M337495</link>
      <description>&lt;P&gt;Thanks for the code you sent.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For BHAR 252 days, for 2021 which is the last year in my dataset, I should not have any values after running the codes&amp;nbsp; as I do not have data for 252 days ahead for them. But when I run the code, BHAR have value until the end of my dataset (20211231). That is why I asked question about the codes.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jan 2023 00:48:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853890#M337495</guid>
      <dc:creator>Fer_</dc:creator>
      <dc:date>2023-01-15T00:48:55Z</dc:date>
    </item>
    <item>
      <title>Re: 1 year (252 days) Buy and hold abnormal return for daily data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853892#M337496</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/438372"&gt;@Fer_&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for the code you sent.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For BHAR 252 days, for 2021 which is the last year in my dataset, I should not have any values after running the codes&amp;nbsp; as I do not have data for 252 days ahead for them. But when I run the code, BHAR have value until the end of my dataset (20211231). That is why I asked question about the codes.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;WINDOW_START allows you to join the aggregated values to the beginning of the window.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  do cusip='11001','11999';
    do year='01jun2020'd to '20feb2021'd;
      ret=rand('uniform',-0.09,0.09);
      vwretd=rand('uniform',-0.09,0.09);
      output;
    end;
  end;
  format year yymmddn8.;
run;

data inter (drop=_:);
  set have;
  by cusip notsorted;

  if first.cusip then call missing(_obs,_sum_log_cusip_ret_plus1,_sum_log_index_ret_plus1);
  _obs+1;
  
  _sum_log_cusip_ret_plus1 + log(1+ret)    - ifn(_obs&amp;gt;252,lag252(log(1+ret)),0) ;

  _sum_log_index_ret_plus1 + log(1+vwretd) - ifn(_obs&amp;gt;252,lag252(log(1+vwretd)),0);

  window_start = lag251(year) ;
  format window_start yymmddn8.;

  if _obs&amp;gt;=252 ;
  bhar_252 =  exp(_sum_log_cusip_ret_plus1) - exp(_sum_log_index_ret_plus1) ;
run;

data want;
  merge have(rename=(year=date)) inter(keep=cusip window_start bhar_252 year rename=(window_start=date year=window_end));
  by cusip date;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1673745672409.png" style="width: 615px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/79409i0AE94500FC540EB9/image-dimensions/615x463?v=v2" width="615" height="463" role="button" title="Patrick_0-1673745672409.png" alt="Patrick_0-1673745672409.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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Jan 2023 01:22:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/1-year-252-days-Buy-and-hold-abnormal-return-for-daily-data/m-p/853892#M337496</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-01-15T01:22:06Z</dc:date>
    </item>
  </channel>
</rss>

