<?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: computing a rolling centered median in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/computing-a-rolling-centered-median/m-p/457385#M14153</link>
    <description>&lt;P&gt;Do something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   infile "c:\Users\Peter\Downloads\example.csv" firstobs=2 dlm=",";
   informat Time datetime23.3 seconds_time 10. RateBid 10.8 RateAsk 10.8;
   format Time datetime23.3;
   input Time RateBid RateAsk seconds_time days;

   midquote=(RateBid+RateAsk)/2;
run;

proc expand data=have out=want;
   id time;
   convert midquote=rollingmedian / transformout=(cmovmed 50);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Whenever you are to compute rolling statistics, think of &lt;A href="http://documentation.sas.com/?docsetId=etsug&amp;amp;docsetTarget=etsug_expand_details19.htm&amp;amp;docsetVersion=14.3&amp;amp;locale=en" target="_self"&gt;PROC EXPAND&lt;/A&gt; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 25 Apr 2018 16:23:29 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2018-04-25T16:23:29Z</dc:date>
    <item>
      <title>computing a rolling centered median</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/computing-a-rolling-centered-median/m-p/457373#M14152</link>
      <description>&lt;P&gt;Hello sas community!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My issue is the following. I have a large dataset containing ultra high frequency data (tick data), which I want to filter for outliers as suggested in the literature:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;Time&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;&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; RateBid&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; RateAsk .....&lt;/DIV&gt;&lt;DIV&gt;01.01.2015:17:12:12.445&amp;nbsp;&amp;nbsp; xxxxxxxxxx&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; xxxxxxxxx&lt;BR /&gt;01.01.2015:17:13:32.565&amp;nbsp;&amp;nbsp; xxxxxxxxxx&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; xxxxxxxxx&lt;BR /&gt;01.01.2015:17:13:40.685&amp;nbsp;&amp;nbsp; xxxxxxxxxx&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; xxxxxxxxx&lt;BR /&gt;01.01.2015:17:14:59.895&amp;nbsp;&amp;nbsp; 1.32473 &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; 1.32487&lt;BR /&gt;01.01.2015:17:14:59.995 &amp;nbsp; 1.86743 &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; 1.97473&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;An example.csv is attached below. I have already removed many obvious data anomalies and now want to filter for outliers as suggested in the literature (e.g. Barndorff-Nielsen Hansen Lunde Shephard (2009) if any of you are interested).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My specific issue is:&lt;/P&gt;&lt;P&gt;I want to delete all entries for which the so called mid-quote ((RateBid+RateAsk)/2) deviated by more than 10 mean absolute deviations from a rolling centered median (excluding the observation under consideration) of the 50 observations around the one considered (so 25 before and 25 after).&amp;nbsp; Here to be honest, I cannot figure out how to construct such a measure in sas.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To clarify, I need to compute a "rolling" median - let's call it M - that goes through the sample step by step and is constructed such that:&lt;/P&gt;&lt;P&gt;for given observations e.g. t1, t2,....,t25, tk ,tk+1,...,tk+25 ,&amp;nbsp; for observation tk the median is only computed of the values (t1-t25 and tk+1 to tk+25). And this has to run through all the observations in the sample. This is to ensure that unusual outliers, that are not in line with surrounding observations are removed, without removing any that might be e.g. the first after a discrete jump.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope you can help me with my issue. Thank you very much in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards&lt;/P&gt;</description>
      <pubDate>Wed, 25 Apr 2018 15:54:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/computing-a-rolling-centered-median/m-p/457373#M14152</guid>
      <dc:creator>NewSASuser2018</dc:creator>
      <dc:date>2018-04-25T15:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: computing a rolling centered median</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/computing-a-rolling-centered-median/m-p/457385#M14153</link>
      <description>&lt;P&gt;Do something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   infile "c:\Users\Peter\Downloads\example.csv" firstobs=2 dlm=",";
   informat Time datetime23.3 seconds_time 10. RateBid 10.8 RateAsk 10.8;
   format Time datetime23.3;
   input Time RateBid RateAsk seconds_time days;

   midquote=(RateBid+RateAsk)/2;
run;

proc expand data=have out=want;
   id time;
   convert midquote=rollingmedian / transformout=(cmovmed 50);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Whenever you are to compute rolling statistics, think of &lt;A href="http://documentation.sas.com/?docsetId=etsug&amp;amp;docsetTarget=etsug_expand_details19.htm&amp;amp;docsetVersion=14.3&amp;amp;locale=en" target="_self"&gt;PROC EXPAND&lt;/A&gt; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Apr 2018 16:23:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/computing-a-rolling-centered-median/m-p/457385#M14153</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-04-25T16:23:29Z</dc:date>
    </item>
    <item>
      <title>Re: computing a rolling centered median</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/computing-a-rolling-centered-median/m-p/457467#M14156</link>
      <description>&lt;P&gt;Please mark the post as accepted solution if it solved your problem &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Apr 2018 19:22:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/computing-a-rolling-centered-median/m-p/457467#M14156</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-04-25T19:22:44Z</dc:date>
    </item>
    <item>
      <title>Re: computing a rolling centered median</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/computing-a-rolling-centered-median/m-p/457550#M14158</link>
      <description>I will definitely do so. First thing in the morning I will check whether it did!&lt;BR /&gt;&lt;BR /&gt;Thanks for the suggested solution and the friendly reminder!</description>
      <pubDate>Wed, 25 Apr 2018 22:18:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/computing-a-rolling-centered-median/m-p/457550#M14158</guid>
      <dc:creator>NewSASuser2018</dc:creator>
      <dc:date>2018-04-25T22:18:28Z</dc:date>
    </item>
    <item>
      <title>Re: computing a rolling centered median</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/computing-a-rolling-centered-median/m-p/457690#M14166</link>
      <description>I don't know why, but the solution triggers a weird error message for me. All of a sudden sas thinks that memory is insufficient. Don't know why.</description>
      <pubDate>Thu, 26 Apr 2018 12:22:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/computing-a-rolling-centered-median/m-p/457690#M14166</guid>
      <dc:creator>NewSASuser2018</dc:creator>
      <dc:date>2018-04-26T12:22:04Z</dc:date>
    </item>
    <item>
      <title>Re: computing a rolling centered median</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/computing-a-rolling-centered-median/m-p/457691#M14167</link>
      <description>&lt;P&gt;Can you post your error message?&lt;/P&gt;</description>
      <pubDate>Thu, 26 Apr 2018 12:32:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/computing-a-rolling-centered-median/m-p/457691#M14167</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-04-26T12:32:28Z</dc:date>
    </item>
    <item>
      <title>Re: computing a rolling centered median</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/computing-a-rolling-centered-median/m-p/457730#M14168</link>
      <description>&lt;P&gt;Yes, sure:&lt;BR /&gt;&lt;BR /&gt;ERROR: Unable to allocate sufficient memory. At least 1329709K bytes were requested, but only&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 68786K were available. You must either increase the amount of memory available, or&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; approach the problem differently.&lt;BR /&gt;ERROR: The SAS System stopped processing this step because of insufficient memory.&lt;BR /&gt;&lt;BR /&gt;however, there should not be an issue. I have 16GB RAM and in my orking directories there is more than enough disc space available.&lt;BR /&gt;&lt;BR /&gt;any thoughts?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what i get when I run proc options group=memory:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Group=MEMORY
 SORTSIZE=1073741824
                   Specifies the amount of memory that is available to the SORT procedure.
 SUMSIZE=0         Specifies a limit on the amount of memory that is available for data
                   summarization procedures when class variables are active.
 MAXMEMQUERY=0     Specifies the maximum amount of memory that is allocated for procedures.
 MEMBLKSZ=16777216 Specifies the memory block size for Windows memory-based libraries.
 MEMMAXSZ=2147483648
                   Specifies the maximum amount of memory to allocate for using memory-based
                   libraries.
 LOADMEMSIZE=0     Specifies a suggested amount of memory that is needed for executable programs
                   loaded by SAS.
 MEMSIZE=2147483648
                   Specifies the limit on the amount of virtual memory that can be used during a
                   SAS session.
 REALMEMSIZE=0     Specifies the amount of real memory SAS can expect to allocate&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Apr 2018 13:28:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/computing-a-rolling-centered-median/m-p/457730#M14168</guid>
      <dc:creator>NewSASuser2018</dc:creator>
      <dc:date>2018-04-26T13:28:56Z</dc:date>
    </item>
  </channel>
</rss>

