<?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: Add index number around an event date in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Add-index-number-around-an-event-date/m-p/107048#M29822</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Anna -&lt;/P&gt;&lt;P&gt;Not sure if I fully understand what you would like to see - I will give it another try (assuming that you have access to SAS/ETS software for the time being).&lt;/P&gt;&lt;P&gt;I think what you are asking for is first of all how to fill gaps in your time id (date variable) and then to calculate relday, correct?&lt;/P&gt;&lt;P&gt;If so, running the following code:&lt;/P&gt;&lt;P&gt;*first fill gaps in timeid;&lt;/P&gt;&lt;P&gt;proc timeseries data=want out=temp;&lt;/P&gt;&lt;P&gt;id date interval=day accumulate=total;&lt;/P&gt;&lt;P&gt;var abn_d;&lt;/P&gt;&lt;P&gt;var rating_date / setmissing=prev;&lt;/P&gt;&lt;P&gt;by eventid;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;*then calculate relday;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set temp;&lt;/P&gt;&lt;P&gt;relday=date-rating_date;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;results in:&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="3093" alt="Reldat.JPG" class="jive-image-thumbnail jive-image" src="https://communities.sas.com/legacyfs/online/3093_Reldat.JPG" width="450" /&gt;&lt;/P&gt;&lt;P&gt;If this is not what you have in mind a illustration of WANT would be useful.&lt;/P&gt;&lt;P&gt;Thanks,&lt;BR /&gt;Udo (aka Undo)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 12 Feb 2013 22:22:39 GMT</pubDate>
    <dc:creator>udo_sas</dc:creator>
    <dc:date>2013-02-12T22:22:39Z</dc:date>
    <item>
      <title>Add index number around an event date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-index-number-around-an-event-date/m-p/107045#M29819</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am doing an event study research project. I need to calculate the total abnormal return (abn_d) around each event. Since I need to try different time window, I would like to add a index date relative the event date. If&amp;nbsp; date = rating_date, relday=0; if the date is the earlier date , relday =-1, or -2, -3.....; if the date is after the rating_date reladay = +1, +2, +3...... But my actual date is not continuous, there are missing dates, so I cannot use date+1 , +2 +3...or date-1, -2, -3.. to reach the goal.&lt;/P&gt;&lt;P&gt;II attached the file. My goal is to create a new variable "relday" to show the date relative to rating_date, then I can choose the time window ( e.g. (-10,+5) ) and calculate the sum of abn_d over this time window. Again, the attached file is a simpler version of my actual data.&lt;/P&gt;&lt;P&gt;I really appreciate helps from the SAS experts here.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Feb 2013 17:34:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-index-number-around-an-event-date/m-p/107045#M29819</guid>
      <dc:creator>Anna_Guo</dc:creator>
      <dc:date>2013-02-12T17:34:20Z</dc:date>
    </item>
    <item>
      <title>Re: Add index number around an event date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-index-number-around-an-event-date/m-p/107046#M29820</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello -&lt;/P&gt;&lt;P&gt;Does this address your "relday" question?&lt;/P&gt;&lt;P&gt;data want; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; relday=date-rating_date;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Results in:&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Reldat.JPG" class="jive-image" src="https://communities.sas.com/legacyfs/online/3092_Reldat.JPG" /&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Udo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Feb 2013 19:22:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-index-number-around-an-event-date/m-p/107046#M29820</guid>
      <dc:creator>udo_sas</dc:creator>
      <dc:date>2013-02-12T19:22:30Z</dc:date>
    </item>
    <item>
      <title>Re: Add index number around an event date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-index-number-around-an-event-date/m-p/107047#M29821</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Undo, thank you.&lt;/P&gt;&lt;P&gt;But the relday is not continuous number. I would like to see all continuous integers: -9, -10, -2, -3... are missing for relday. I need to make sure when I specify the time window (-5,+5), there are same numbers of trading day for each firm.&lt;/P&gt;&lt;P&gt;Anna&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Feb 2013 19:38:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-index-number-around-an-event-date/m-p/107047#M29821</guid>
      <dc:creator>Anna_Guo</dc:creator>
      <dc:date>2013-02-12T19:38:38Z</dc:date>
    </item>
    <item>
      <title>Re: Add index number around an event date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-index-number-around-an-event-date/m-p/107048#M29822</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Anna -&lt;/P&gt;&lt;P&gt;Not sure if I fully understand what you would like to see - I will give it another try (assuming that you have access to SAS/ETS software for the time being).&lt;/P&gt;&lt;P&gt;I think what you are asking for is first of all how to fill gaps in your time id (date variable) and then to calculate relday, correct?&lt;/P&gt;&lt;P&gt;If so, running the following code:&lt;/P&gt;&lt;P&gt;*first fill gaps in timeid;&lt;/P&gt;&lt;P&gt;proc timeseries data=want out=temp;&lt;/P&gt;&lt;P&gt;id date interval=day accumulate=total;&lt;/P&gt;&lt;P&gt;var abn_d;&lt;/P&gt;&lt;P&gt;var rating_date / setmissing=prev;&lt;/P&gt;&lt;P&gt;by eventid;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;*then calculate relday;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set temp;&lt;/P&gt;&lt;P&gt;relday=date-rating_date;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;results in:&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="3093" alt="Reldat.JPG" class="jive-image-thumbnail jive-image" src="https://communities.sas.com/legacyfs/online/3093_Reldat.JPG" width="450" /&gt;&lt;/P&gt;&lt;P&gt;If this is not what you have in mind a illustration of WANT would be useful.&lt;/P&gt;&lt;P&gt;Thanks,&lt;BR /&gt;Udo (aka Undo)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Feb 2013 22:22:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-index-number-around-an-event-date/m-p/107048#M29822</guid>
      <dc:creator>udo_sas</dc:creator>
      <dc:date>2013-02-12T22:22:39Z</dc:date>
    </item>
    <item>
      <title>Re: Add index number around an event date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-index-number-around-an-event-date/m-p/107049#M29823</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Udo,&lt;/P&gt;&lt;P&gt;Thank you for your help.&amp;nbsp; For the illustration&amp;nbsp; table you provided, for the date of March 15, 1996, I would like to see the relday=-9 ( not -11),&amp;nbsp; and the dates when abn_d missing, I would like to see relday also missing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyone can give me more help?&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;Anna&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 12 Feb 2013 22:55:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-index-number-around-an-event-date/m-p/107049#M29823</guid>
      <dc:creator>Anna_Guo</dc:creator>
      <dc:date>2013-02-12T22:55:46Z</dc:date>
    </item>
    <item>
      <title>Re: Add index number around an event date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-index-number-around-an-event-date/m-p/107050#M29824</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Please help!!&lt;/P&gt;&lt;P&gt;Anna&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Feb 2013 19:54:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-index-number-around-an-event-date/m-p/107050#M29824</guid>
      <dc:creator>Anna_Guo</dc:creator>
      <dc:date>2013-02-13T19:54:47Z</dc:date>
    </item>
    <item>
      <title>Re: Add index number around an event date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-index-number-around-an-event-date/m-p/107051#M29825</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure if this is what you want:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;/*to locate the record most close to rating_date*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; do until (last.eventid);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set test.test;&lt;/P&gt;&lt;P&gt;by eventid date;&lt;/P&gt;&lt;P&gt;_dif=abs(RATING_DATE-date);&lt;/P&gt;&lt;P&gt;_mindif=min(_mindif,_dif);&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /*the get the seq no of that record*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; do _n_=1 by 1 until (last.eventid);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set test.test;&lt;/P&gt;&lt;P&gt;by eventid date;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if abs(RATING_DATE-date)=_mindif then _tp=_n_;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /*assign the new seq no*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; do relday=-_tp by 1 until (last.eventid);&lt;/P&gt;&lt;P&gt;&amp;nbsp; set test.test;&lt;/P&gt;&lt;P&gt;by eventid date;&lt;/P&gt;&lt;P&gt;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; drop _:;&lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Feb 2013 21:04:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-index-number-around-an-event-date/m-p/107051#M29825</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-02-13T21:04:45Z</dc:date>
    </item>
    <item>
      <title>Re: Add index number around an event date</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Add-index-number-around-an-event-date/m-p/107052#M29826</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hai.Kuo&lt;/P&gt;&lt;P&gt;Thank you very much!!!&lt;/P&gt;&lt;P&gt;This is exactly what I want. I did the other event study last year and I used excel (vlookup) to add the relative trading date index to my data. It was painful. I wished I had joined SAS communities earlier.&lt;/P&gt;&lt;P&gt;Very much appreciate your help!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Feb 2013 22:35:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Add-index-number-around-an-event-date/m-p/107052#M29826</guid>
      <dc:creator>Anna_Guo</dc:creator>
      <dc:date>2013-02-13T22:35:41Z</dc:date>
    </item>
  </channel>
</rss>

