<?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: Challenging command -Return volatilities in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115727#M32009</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No worries at all, you have been exceptionally helpful. I will test out Ksharps code and keep playing with this data!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 05 Nov 2012 06:45:12 GMT</pubDate>
    <dc:creator>kt_uwa1990</dc:creator>
    <dc:date>2012-11-05T06:45:12Z</dc:date>
    <item>
      <title>Challenging command -Return volatilities</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115707#M31989</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt; font-family: 'Times New Roman','serif';"&gt;Hi all&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt; font-family: 'Times New Roman','serif';"&gt;I am having difficulty engineering a code on SAS. I am new to SAS and finding this extremely difficult. I would greatly appreciative if you could help me here.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt; font-family: 'Times New Roman','serif';"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt; font-family: 'Times New Roman','serif';"&gt;I have outlined my objectives below:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt; font-family: 'Times New Roman','serif';"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt; font-family: 'Times New Roman','serif';"&gt;-For each PERMNO (company identifier) with DISTCD 1262 or 1272 (t=0), calculate the daily standard deviation in RET for two years before (t= -1,-2) and two years after (t= +1,+2) surrounding the day of this event.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt; font-family: 'Times New Roman','serif';"&gt;-Then create a column called BEFORE. This is an average daily standard deviation across the years (–1,–2).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt; font-family: 'Times New Roman','serif';"&gt; -Then create a column called AFTER. This is an average daily standard deviation across the years (+1, +2). &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt; font-family: 'Times New Roman','serif';"&gt;-Then subtract BEFORE-AFTER, to produce a difference (DIFF).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt; font-family: 'Times New Roman','serif';"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt; font-family: 'Times New Roman','serif';"&gt;A successful code should let me refer back to a DISTCD of 1272 or 1262 and see the DIFF at that specific date. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt; font-family: 'Times New Roman','serif';"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt; font-family: 'Times New Roman','serif';"&gt;I have been stuck for a while on this and find it challenging. I highly encourage help and useful code on this problem (please see data attachment&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt; font-family: 'Times New Roman','serif';"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt; font-family: 'Times New Roman','serif';"&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12.0pt; font-family: 'Times New Roman','serif';"&gt;Katy&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Nov 2012 01:02:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115707#M31989</guid>
      <dc:creator>kt_uwa1990</dc:creator>
      <dc:date>2012-11-02T01:02:34Z</dc:date>
    </item>
    <item>
      <title>Re: Challenging command -Return volatilities</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115708#M31990</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You should post some small sample data and the &lt;STRONG&gt;result&lt;/STRONG&gt; you want . Your attachment is to huge ,I am not going to work with it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Nov 2012 02:16:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115708#M31990</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-11-02T02:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: Challenging command -Return volatilities</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115709#M31991</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am sorry about that, forgive me, I am still famailarising myself with SAS communities and did not realise that this database size is too large. Thank you for your comments, I have since followed your instructions and reduced the sample size by 2/3. Please see the attached data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In response to the result I want, the table produced should look something like this (see the attached picture). Please note this is a hypothetical representation as I still need to create the code to find my results.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;IMG __jive_id="2672" alt="table_desired.JPG" class="jive-image-thumbnail jive-image" src="https://communities.sas.com/legacyfs/online/2672_table_desired.JPG" width="450" /&gt;&lt;/P&gt;&lt;P&gt;You will note that SDEV should be calculated for each observation. SDEV is just the standard deviation between todays return and yesterday’s return.&amp;nbsp; For example, the standard deviation of RET 0.0021 and 0.0033 is 0.000849.&lt;/P&gt;&lt;P&gt;While BEFORE, AFTER, and DIFF are just calculated for those observations with either 1262 or 1272 in the DISTCD. I hope my explanations of the variables attached to the earlier post are adequate. If not, please let me know and I will provide further detail. BEFORE and AFTER are just averages of the PERMNOS previous two year SDEV and post two year SDEV.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Once again, I thank you for your response to my query. I very much hope you will be able to help me in solving my problem.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Nov 2012 03:00:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115709#M31991</guid>
      <dc:creator>kt_uwa1990</dc:creator>
      <dc:date>2012-11-02T03:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: Challenging command -Return volatilities</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115710#M31992</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm afraid your test_vol data table seems to be corrupt.&amp;nbsp; You have lots of null values and repeated rows, and the data is disordered.&amp;nbsp; I ran the following code on your second data and got some results but I don't think that is what you expected.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proc import&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datafile = 'C:\Users\Public\Temp\test_vol.dbf' &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Out&amp;nbsp;&amp;nbsp;&amp;nbsp; = test_vol&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DBMS = DBF&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Replace &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;Run ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data Stdcalc (Rename = (DateRet = Date DclrRet = DclrDt DistRet = Distcd PrcRet = Prc Check = Ret)) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Length Permno DateRet DclrRet DistRet PrcRet Check before after diff 8 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set test_vol ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Format&amp;nbsp;&amp;nbsp;&amp;nbsp; DateRet&amp;nbsp;&amp;nbsp;&amp;nbsp; DclrRet Date9. ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; By&amp;nbsp;&amp;nbsp;&amp;nbsp; Permno Notsorted ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DateRet&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp;&amp;nbsp;&amp;nbsp; Lag (Date) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DistRet =&amp;nbsp;&amp;nbsp; Lag (Distcd) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; DclrRet&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp;&amp;nbsp;&amp;nbsp; Lag (Dclrdt) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PrcRet&amp;nbsp; =&amp;nbsp;&amp;nbsp; Lag (Prc) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Check&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp;&amp;nbsp;&amp;nbsp; Lag (Ret) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; First.Permno&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Then Check&amp;nbsp;&amp;nbsp;&amp;nbsp; = . ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Prior&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp;&amp;nbsp;&amp;nbsp; Lag (Check) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Before&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Std (Prior, check) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; After&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp;&amp;nbsp;&amp;nbsp; Std (Check, Ret) ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Diff&amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp;&amp;nbsp;&amp;nbsp; Before - After ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If&amp;nbsp;&amp;nbsp;&amp;nbsp; Prior = . Or Diff = . then&amp;nbsp;&amp;nbsp;&amp;nbsp; delete ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; If&amp;nbsp;&amp;nbsp;&amp;nbsp; DistRet&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;gt; . then output ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Keep Permno DateRet DclrRet DistRet PrcRet Check before after diff ;&lt;/P&gt;&lt;P&gt;Run ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data&amp;nbsp;&amp;nbsp;&amp;nbsp; Want ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set&amp;nbsp;&amp;nbsp;&amp;nbsp; Stdcalc (Where = (Distcd IN (1262, 1272))) ;&lt;/P&gt;&lt;P&gt;Run ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Permno&amp;nbsp;&amp;nbsp;&amp;nbsp; Date&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DclrDt&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Distcd&amp;nbsp;&amp;nbsp;&amp;nbsp; Prc&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Ret&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; before&amp;nbsp;&amp;nbsp; after&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; diff &lt;/P&gt;&lt;P&gt;11648&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 29DEC2010 21DEC2010&amp;nbsp;&amp;nbsp; 1262&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 20.1755&amp;nbsp; 0.023271&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.0302903332&amp;nbsp; -0.030290333 &lt;/P&gt;&lt;P&gt;10239&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 16NOV2007 07NOV2007&amp;nbsp; 1272&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 27.41&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.015362&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0 &lt;/P&gt;&lt;P&gt;10239&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 16NOV2007 07NOV2007&amp;nbsp; 1272&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 27.41&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.015362&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0 &lt;/P&gt;&lt;P&gt;10239&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 16NOV2007 07NOV2007&amp;nbsp; 1272&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 27.41&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.015362&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0 &lt;/P&gt;&lt;P&gt;etc&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Richard in Oz&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Nov 2012 04:28:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115710#M31992</guid>
      <dc:creator>RichardinOz</dc:creator>
      <dc:date>2012-11-02T04:28:25Z</dc:date>
    </item>
    <item>
      <title>Re: Challenging command -Return volatilities</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115711#M31993</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Richard in Oz&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;First, thank you very much for your assistance. I greatly appreciate your help with this!&lt;/P&gt;&lt;P&gt;-I noticed you mentioned there seems to be a lot of duplicates in my data.Maybe we could use the following code to prevent this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data test_vol; set test; vol; if Permno=lag(permno) and date=lag(date) and distcd=lag(distcd) then delete; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Also yes there should be a few blanks for distcd, this is OK. However if there are blanks in RET it is worthwhile deleting these also.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data test_vol; set test; vol; if RET=. then delete; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Ordering the data can be obtained by inserting the code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC sort data=test_vol; by PERMNO DATE; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am a bit troubled by the results generated your code above. I notice there is no SDEV column. Do you know why there are so many zeros in before, after and diff? I imagine there should be at least some SDEV two years before to populate the BEFORE estimate. Likewise, there should be at least some SDEV two years after, to populate the AFTER estimate. Though I'm very happy we are getting somewhere! Progress is being made! Thank you very much for your contribution hopefully we can tackle this problem together!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Katy&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Nov 2012 04:57:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115711#M31993</guid>
      <dc:creator>kt_uwa1990</dc:creator>
      <dc:date>2012-11-02T04:57:44Z</dc:date>
    </item>
    <item>
      <title>Re: Challenging command -Return volatilities</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115712#M31994</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;OK. If I understand what you mean.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;
proc sql;
create table temp as
 select h.*,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case when&amp;nbsp; h.distcd in (1262 1272) then (select std(ret) from have where permno = h.permno and date between intnx('year',-1,h.date,'s') and h.date) else . end as std_one_year_before ,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case when&amp;nbsp; h.distcd in (1262 1272) then (select std(ret) from have where permno = h.permno and date between intnx('year',-2,h.date,'s') and h.date) else . end as std_two_year_before ,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case when&amp;nbsp; h.distcd in (1262 1272) then (select std(ret) from have where permno = h.permno and date between h.date and&amp;nbsp; intnx('year',1,h.date,'s')) else . end as std_one_year_after ,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case when&amp;nbsp; h.distcd in (1262 1272) then (select std(ret) from have where permno = h.permno and date between h.date and&amp;nbsp; intnx('year',2,h.date,'s')) else . end as std_two_year_after
&amp;nbsp; from test_vol as h;

create table want as
 select *,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mean(std_one_year_before) as mean_one_year_before ,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mean(std_two_year_before) as mean_two_year_before ,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; calculated&amp;nbsp; mean_one_year_before - calculated mean_two_year_before as diff_before ,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mean(std_one_year_after) as mean_one_year_after ,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; mean(std_two_year_after) as mean_two_year_after ,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; calculated&amp;nbsp; mean_one_year_after - calculated mean_two_year_after as diff_after 
&amp;nbsp; from temp
&amp;nbsp;&amp;nbsp; group by permno;
quit;



&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Nov 2012 05:12:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115712#M31994</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-11-02T05:12:54Z</dc:date>
    </item>
    <item>
      <title>Re: Challenging command -Return volatilities</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115713#M31995</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Ksharp&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for getting back to me so quickly!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;May I please ask whether the variable: "mean_two_year_before" represents the average SDEV for a specific company (permno) across the two years prior to the DISTCD 1262 or 1272 date? Also whether "mean_two_year_after" represents the average SDEV for a specific company (permno) across the two years after the&amp;nbsp; DISTCD 1262 or 1272 date?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As I am thinking of creating the following variable: "mean_two_year_before" - "mean_two_year_after" = DIFF&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;-Katy&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Nov 2012 05:38:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115713#M31995</guid>
      <dc:creator>kt_uwa1990</dc:creator>
      <dc:date>2012-11-02T05:38:24Z</dc:date>
    </item>
    <item>
      <title>Re: Challenging command -Return volatilities</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115714#M31996</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes.&lt;/P&gt;&lt;P&gt;the variable: "mean_two_year_before" represents the average SDEV&lt;STRONG&gt;(two_year_before)&lt;/STRONG&gt;&amp;nbsp; for a specific company (permno) across the two years prior to the &lt;STRONG&gt;current observation's&lt;/STRONG&gt;&amp;nbsp; DISTCD 1262 or 1272 date?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Nov 2012 06:03:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115714#M31996</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-11-02T06:03:01Z</dc:date>
    </item>
    <item>
      <title>Re: Challenging command -Return volatilities</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115715#M31997</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Calibri','sans-serif';"&gt;Ok thank you so much K sharp. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Calibri','sans-serif';"&gt;If it is ok with you, may I please ask one final question. I would like to ask, how would the code change if we remove the 1262 and 1272 restriction? &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Calibri','sans-serif';"&gt;That is, for each PERMNO calculate the daily standard deviation (SDEV)&amp;nbsp; for RET two years before (t= -1,-2) and two years after (t= +1,+2) surrounding each date recorded, or each observation.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Calibri','sans-serif';"&gt;So the column called BEFORE, the average daily standard deviation across the years (–1,–2) is calculated for all observations.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Calibri','sans-serif';"&gt;And the column called AFTER. This is an average daily standard deviation across the years (+1, +2) is also calculated for all observations.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Calibri','sans-serif';"&gt;-I then subtract BEFORE-AFTER, to produce a difference column (DIFF) which should be produced for all the observations.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Calibri','sans-serif';"&gt; Is this possible to see in code? &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Nov 2012 06:13:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115715#M31997</guid>
      <dc:creator>kt_uwa1990</dc:creator>
      <dc:date>2012-11-02T06:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: Challenging command -Return volatilities</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115716#M31998</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is more easy. Remove the case clause in SQL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;
proc sql;
create table temp as
 select h.*,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select std(ret) from test_vol where permno = h.permno and date between intnx('year',h.date,-1,'s') and h.date) as std_one_year_before ,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select std(ret) from test_vol where permno = h.permno and date between intnx('year',h.date,-2,'s') and h.date) as std_two_year_before ,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select std(ret) from test_vol where permno = h.permno and date between h.date and&amp;nbsp; intnx('year',h.date,1,'s')) as std_one_year_after ,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select std(ret) from test_vol where permno = h.permno and date between h.date and&amp;nbsp; intnx('year',h.date,2,'s')) as std_two_year_after
&amp;nbsp; from test_vol as h;quit;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: xia keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Nov 2012 06:46:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115716#M31998</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-11-02T06:46:10Z</dc:date>
    </item>
    <item>
      <title>Re: Challenging command -Return volatilities</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115717#M31999</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much. I find that this code takes a while to run on my SAS, just checking, is it the same for you? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Nov 2012 06:56:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115717#M31999</guid>
      <dc:creator>kt_uwa1990</dc:creator>
      <dc:date>2012-11-02T06:56:58Z</dc:date>
    </item>
    <item>
      <title>Re: Challenging command -Return volatilities</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115718#M32000</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes. I also need some time to run . maybe your data is a little big .&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Nov 2012 06:59:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115718#M32000</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-11-02T06:59:49Z</dc:date>
    </item>
    <item>
      <title>Re: Challenging command -Return volatilities</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115719#M32001</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My big concern with the data is that there is no unique key combination.&amp;nbsp; Initially I thought that missing values for DISTCD (not just a few - most are missing) did not matter because I could find the corresponding value of PERMNO but that did not work because it proved to be a many to many relationship.&amp;nbsp; It seemed at first from your data that maybe there was an implicit order, PERMNO and then DATE but even that failed in the second data set.&amp;nbsp; It would worry me that you are trying to calculate a fairly complex result from data that is so shaky.&amp;nbsp; I urge you to make sure the data is clean before you calculate and use these results.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Richard in Oz&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Nov 2012 11:16:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115719#M32001</guid>
      <dc:creator>RichardinOz</dc:creator>
      <dc:date>2012-11-02T11:16:43Z</dc:date>
    </item>
    <item>
      <title>Re: Challenging command -Return volatilities</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115720#M32002</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you for your concern Richard, do you have any suggestions to improving the PERMNO and DATE order? Do you mean that these are not consecutive? This is not too much of a problem because the focus here is on average volatiles (standard deviations). My main objective is just to compare the typical size of the standard deviation two years before with two years after.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am having difficulty with the 1st code produced actually. It appears that:&lt;/P&gt;&lt;P&gt;"mean_two_year_after"&amp;nbsp; has the same value as "mean_two_year_before". This cannot be correct. I suspect there is a problem with the code, maybe at the standard devation calculations:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table temp as&lt;/P&gt;&lt;P&gt;select h.*,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case when&amp;nbsp; h.distcd in (1262 1272) then (select std(ret) from have where permno = h.permno and date between intnx('year',-1,h.date,'s') and h.date) else . end as std_one_year_before ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case when&amp;nbsp; h.distcd in (1262 1272) then (select std(ret) from have where permno = h.permno and date between intnx('year',-2,h.date,'s') and h.date) else . end as std_two_year_before ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case when&amp;nbsp; h.distcd in (1262 1272) then (select std(ret) from have where permno = h.permno and date between h.date and&amp;nbsp; intnx('year',1,h.date,'s')) else . end as std_one_year_after ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; case when&amp;nbsp; h.distcd in (1262 1272) then (select std(ret) from have where permno = h.permno and date between h.date and&amp;nbsp; intnx('year',2,h.date,'s')) else . end as std_two_year_after&lt;/P&gt;&lt;P&gt;&amp;nbsp; from test_vol as h;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I see that it contains: "&amp;nbsp; case when&amp;nbsp; h.distcd in (1262 1272)" this worries me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I shall provide an example of what I am looking to do, if permno 10008 had 1262 on 03/07/2010... I would like to calculate permos 10008 average standard deviation for 03/07/2008 to 03/07/2010, this is known as before (note the daily standard deviations used in the mean computation do not have to be associated&amp;nbsp; with their own 1262 and 1272 distcd). Then, following the same pattern, I would also like to calculate permnos 10008&amp;nbsp; average standard deviation from 03/07/2010 to 03/07/2012. If my data doesn't give me the full two years before, and after, that is OK just utilize the observations that I have. Are you sure the code above accurately does this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have attempted to use your second code without the 1262 and 1272 but it appears that this is taking too long with my data.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 02 Nov 2012 23:57:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115720#M32002</guid>
      <dc:creator>kt_uwa1990</dc:creator>
      <dc:date>2012-11-02T23:57:40Z</dc:date>
    </item>
    <item>
      <title>Re: Challenging command -Return volatilities</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115721#M32003</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm just looking at your question, and the responses, for the first time thus forgive me if I ask some dumb questions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your example wasn't very helpful as your data doesn't have any records for permno 10008.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is DCLRDT supposed to be used for anything?&amp;nbsp; I noticed that it wasn't used in any of the suggested solutions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Permno 10239, has a number of records with DISTCD codes that meet your criteria.&amp;nbsp; And, of those, the date ranges would include the same records regardless of whether one uses the date or the DCLRDT field as the base date.&amp;nbsp; Are you expecting to treat each one of those separately?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regardless of which date is supposed to be used, should the data for that particular date for a particular permno be used for the std devs and, if so, for the years before or the years after or both?&amp;nbsp; Plus, regarding the specification one year before, is that 1 day to one year before, or one year to two years minus 1 day before?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;KSharp's code refers to a file called have.&amp;nbsp; Is there another file I didn't see in your post?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, KSharp had a slight error (I think) in his use of the intnx function which is why you were getting such odd results.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That said, the following may be incorrect as it depends upon your answers to the above questions, whether I correctly understand the problem, and whether my logic is actually correct in accomplishing the task.&amp;nbsp; The code is definitely NOT guaranteed or fully tested:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table met_criterion as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select distinct permno,DCLRDT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from test_vol&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where DISTCD in (1262,1272)&lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table want as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select h.*,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select std(ret) from test_vol where permno = h.permno and date between intnx('year',h.DCLRDT,-1,'s') and h.DCLRDT) as std_one_year_before ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select std(ret) from test_vol where permno = h.permno and date between intnx('year',h.DCLRDT,-2,'s') and h.DCLRDT) as std_two_year_before ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select std(ret) from test_vol where permno = h.permno and date between h.DCLRDT and&amp;nbsp; intnx('year',h.DCLRDT,1,'s')) as std_one_year_after ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select std(ret) from test_vol where permno = h.permno and date between h.DCLRDT and&amp;nbsp; intnx('year',h.DCLRDT,2,'s')) as std_two_year_after&lt;/P&gt;&lt;P&gt;&amp;nbsp; from met_criterion as h;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 03 Nov 2012 15:33:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115721#M32003</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-11-03T15:33:20Z</dc:date>
    </item>
    <item>
      <title>Re: Challenging command -Return volatilities</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115722#M32004</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi art &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you very much for your questions and helpfulness I was beginning to worry this problem may not get resolved. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In response to your questions:&lt;/P&gt;&lt;P&gt;DCLRDT is the date that the distribution code (1262 or 1272) is declared to the market. This being said, this date should act like the premise for the two years before and two years after calculation. I.e.: if the DCLRDT was 01-01-2010 then two years before should extend to 01-01-2008 for DATE and two years after should extend to 01-01-2012 for DATE, with respect to the averages for standard deviation. However the DCLRDT and the DATE for 1262 and 1272 should not be vastly different from one another. Therefore for simplicities sake I encourage using the DATE as the basis or starting point.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If Permno 10239 has a number of 1262s and 1272s which overlap in the +/-2 year date ranges this is ok. The overlap of SDEV information for the same permno is fine. But I would like to treat each 1262 and 1272 separately. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have supplied no file called “have”. To be frank, I am only interested in 2 before and after analysis, not 1yr. I am not sure why this has been included.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does your code supplied satisfy the conditions discussed above?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As there are concerns with the earlier posts. I would also like to ask you: how would your code change if we remove the 1262 and 1272 restriction? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That is, for each PERMNO calculate the daily standard deviation (SDEV) for RET two years before (t= -1,-2) and two years after (t= +1,+2) surrounding each date recorded, or each observation.&lt;/P&gt;&lt;P&gt;So the column called BEFORE, the average daily standard deviation across the years (–1,–2) is calculated for all observations.&lt;/P&gt;&lt;P&gt;And the column called AFTER. This is an average daily standard deviation across the years (+1, +2) is also calculated for all observations.&lt;/P&gt;&lt;P&gt;-I then subtract BEFORE-AFTER, to produce a difference column (DIFF) which should be produced for all the observations.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If is is possible to see code for:&lt;/P&gt;&lt;P&gt;(1) With 1262 and 1272 restriction&lt;/P&gt;&lt;P&gt;(2) And without 1262 and 1272 restriction &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would be unduly grateful. Thank you very much once again.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 04 Nov 2012 17:18:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115722#M32004</guid>
      <dc:creator>kt_uwa1990</dc:creator>
      <dc:date>2012-11-04T17:18:01Z</dc:date>
    </item>
    <item>
      <title>Re: Challenging command -Return volatilities</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115723#M32005</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No, my code didn't meet all of your requirements and I discovered some additional complications in your data.&amp;nbsp; When the distcd codes were added numerous duplicate records were introduced.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The following is an attempt to get rid of the duplicates without losing any of the critical information.&amp;nbsp; You will have to check if it does what I had intended for it to do.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That said, the following does (I think at least) meet your various requirements.&amp;nbsp; However, as for your question about expanding your data records to include calculations for each day, I'll have to leave that for someone more familiar with analyzing this type of data.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here is the approach I took:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC IMPORT OUT= WORK.test_vol_in&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DATAFILE= "C:\art\test_vol.dbf" &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; DBMS=DBF REPLACE;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; GETDELETED=NO;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data contains_distcd;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set test_vol_in;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if not missing(distcd);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data does_not_contain_distcd;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set test_vol_in;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if missing(distcd);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=contains_distcd;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by permno date ret;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data contains_distcd_cleaner;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set contains_distcd;&lt;/P&gt;&lt;P&gt;&amp;nbsp; retain contains_1262 contains_1272 contains_other;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by permno date;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if first.date then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; call missing(contains_1262);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; call missing(contains_1272);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; call missing(contains_other);&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if distcd eq 1262 then contains_1262=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else if distcd eq 1272 then contains_1272=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else contains_other=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if last.date then output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data both;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set does_not_contain_distcd contains_distcd_cleaner;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table met_criterion_1262 as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select distinct permno,date&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from both&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where contains_1262=1&lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table met_criterion_1272 as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select distinct permno,date&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from both&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where contains_1272=1&lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table want_1262 as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select h.*,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select std(ret) from both where permno = h.permno and date between intnx('year',h.date,-2,'s') and h.date) as before ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select std(ret) from both where permno = h.permno and date between h.date and intnx('year',h.date,2,'s')) as after,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; calculated before-calculated after as diff&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from met_criterion_1262 as h&lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table want_1272 as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select h.*,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select std(ret) from both where permno = h.permno and date between intnx('year',h.date,-2,'s') and h.date) as before ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select std(ret) from both where permno = h.permno and date between h.date and intnx('year',h.date,2,'s')) as after,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; calculated before-calculated after as diff&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; from met_criterion_1272 as h&lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 04 Nov 2012 20:32:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115723#M32005</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-11-04T20:32:24Z</dc:date>
    </item>
    <item>
      <title>Re: Challenging command -Return volatilities</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115724#M32006</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This code is thorough and works swimmingly! Thank you thank you thank you, these were the kind of results I was expecting!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Just a quick question. As I also want to find the +/- 2 yr average SDEV for all stocks (regardless of 1262 and 1272 or not) how should I tweak the code? You will notice Ksharp provides a solution, but due to past concerns, is this an incorrect approach to take? I am just thinking surely this approach must be easier than that discussed above. Hmm, there must be a solution for this!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Btw, if duplicate data arises this can be easily solved using: data test_vol_in; set test_vol_in; if permno=lag(permno) and date=lag(date) then delete; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am pleased progress is being made, you provide a very valuable contribution art! Almost there!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Katy&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Nov 2012 01:18:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115724#M32006</guid>
      <dc:creator>kt_uwa1990</dc:creator>
      <dc:date>2012-11-05T01:18:15Z</dc:date>
    </item>
    <item>
      <title>Re: Challenging command -Return volatilities</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115725#M32007</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Arthur.T&lt;/P&gt;&lt;P&gt;Thank you to point out my mistake.&lt;/P&gt;&lt;P&gt;I think I am too long to learn SAS .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best Regard.&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;
proc sql;
create table temp as
 select h.*,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select std(ret) from test_vol where permno = h.permno and date between intnx('year',h.date,-1,'s') and h.date) as std_one_year_before ,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select std(ret) from test_vol where permno = h.permno and date between intnx('year',h.date,-2,'s') and h.date) as std_two_year_before ,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select std(ret) from test_vol where permno = h.permno and date between h.date and&amp;nbsp; intnx('year',h.date,1,'s')) as std_one_year_after ,
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (select std(ret) from test_vol where permno = h.permno and date between h.date and&amp;nbsp; intnx('year',h.date,2,'s')) as std_two_year_after
&amp;nbsp; from test_vol as h;quit;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Nov 2012 01:49:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115725#M32007</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-11-05T01:49:09Z</dc:date>
    </item>
    <item>
      <title>Re: Challenging command -Return volatilities</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115726#M32008</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Katy, Glad to have been able to be of help but, like I said, this is not my area.&amp;nbsp; I am a psychologist, not a statistician or a economist.&amp;nbsp; I'm sure that others can provide more correct guidance, at this point, than I can.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are looking for before and after effects, I would think that you have to decide what constitutes the border between before and after.&amp;nbsp; If it is just ANY of the codes in the field from which you selected the other two, then it is an easy problem to solve.&amp;nbsp; But, not knowing what any of those codes represent, I am hesitant to suggest an approach.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Nov 2012 04:07:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Challenging-command-Return-volatilities/m-p/115726#M32008</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-11-05T04:07:23Z</dc:date>
    </item>
  </channel>
</rss>

