<?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 10-second price difference in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716385#M221393</link>
    <description>&lt;P&gt;Also. Is your data grouped by some ID variable?&lt;/P&gt;</description>
    <pubDate>Wed, 03 Feb 2021 11:23:26 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2021-02-03T11:23:26Z</dc:date>
    <item>
      <title>Computing 10-second price difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716368#M221379</link>
      <description>&lt;P&gt;Suppose that I have the following dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&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; Volume&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Price&lt;/P&gt;&lt;P&gt;10:02:04&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100.25&lt;/P&gt;&lt;P&gt;10:02:07&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;200&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100.35&lt;/P&gt;&lt;P&gt;10:02:14&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;300&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100.55&lt;/P&gt;&lt;P&gt;10:02:18&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100.60&lt;/P&gt;&lt;P&gt;10:02:18&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;300&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100.70&lt;/P&gt;&lt;P&gt;10:02:23&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;200&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100.80&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And, I want to get the following dataset&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&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; Volume&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Price&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Diff&lt;/P&gt;&lt;P&gt;10:02:04&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 100.25&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -0.0045 = (100.25 - 100.70)/100.25 = (price(t)-price(t+10))/price(t)&lt;/P&gt;&lt;P&gt;10:02:07&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;200&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 100.35&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -0.0032 = (100.35 - 100.675)/100.35&lt;/P&gt;&lt;P&gt;10:02:14&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;300&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 100.55&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -0.0012 =&amp;nbsp;(100.55 - 100.675)/100.55&lt;/P&gt;&lt;P&gt;10:02:16&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;100&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 100.60&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -0.0009 =&amp;nbsp;(100.60 - 100.70)/100.60&lt;/P&gt;&lt;P&gt;10:02:16&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;300&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 100.70&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, as you can see, I need to find price change over 10 seconds (p(t) - p(t+10)) and then divide it by p(t). However, there are some issues. First, if I do not have p(t+10), then I need to select the price that is closest to p(t+10). Furthermore, if I have two prices in one second, I need to compute the volume-weighted average price for this second and then use it. For example, in my data, I have an interval of 10:02:07. I do not have a price at 10:02:17 and the closest one is the price at 10:02:16. However, in this interval, I have two prices. Therefore, I am computing the volume-weighted average price for this interval (((100/400)*100.60 + (300/400)*100.70) = 100.675) and then use this one.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please help me with this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope I could explain my question.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 11:01:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716368#M221379</guid>
      <dc:creator>Khaladdin</dc:creator>
      <dc:date>2021-02-03T11:01:30Z</dc:date>
    </item>
    <item>
      <title>Re: Computing 10-second price difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716370#M221380</link>
      <description>&lt;P&gt;Is time an actual SAS Time value?&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 11:07:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716370#M221380</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-03T11:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: Computing 10-second price difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716375#M221385</link>
      <description>&lt;P&gt;Also, why is it 100.70 in the first obs:&amp;nbsp;&lt;SPAN&gt;(100.25 - &lt;STRONG&gt;100.70&lt;/STRONG&gt;)/100.25 ?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Shouldn't that be&amp;nbsp;(100.25 - &lt;STRONG&gt;100.55&lt;/STRONG&gt;)/100.25 ?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 11:12:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716375#M221385</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-03T11:12:01Z</dc:date>
    </item>
    <item>
      <title>Re: Computing 10-second price difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716385#M221393</link>
      <description>&lt;P&gt;Also. Is your data grouped by some ID variable?&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 11:23:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716385#M221393</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-03T11:23:26Z</dc:date>
    </item>
    <item>
      <title>Re: Computing 10-second price difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716386#M221394</link>
      <description>&lt;P&gt;Yes, sorry. It should be 100.55&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 11:23:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716386#M221394</guid>
      <dc:creator>Khaladdin</dc:creator>
      <dc:date>2021-02-03T11:23:39Z</dc:date>
    </item>
    <item>
      <title>Re: Computing 10-second price difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716387#M221395</link>
      <description>&lt;P&gt;No, I do not have ID in my data.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 11:24:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716387#M221395</guid>
      <dc:creator>Khaladdin</dc:creator>
      <dc:date>2021-02-03T11:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: Computing 10-second price difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716389#M221397</link>
      <description>&lt;P&gt;Yes.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 11:24:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716389#M221397</guid>
      <dc:creator>Khaladdin</dc:creator>
      <dc:date>2021-02-03T11:24:22Z</dc:date>
    </item>
    <item>
      <title>Re: Computing 10-second price difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716390#M221398</link>
      <description>In the first observation, it should be (100.25 - 100.55)/100.25</description>
      <pubDate>Wed, 03 Feb 2021 11:25:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716390#M221398</guid>
      <dc:creator>Khaladdin</dc:creator>
      <dc:date>2021-02-03T11:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: Computing 10-second price difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716404#M221407</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Time :time8. Volume Price;
format Time time8.;
datalines;
10:02:04 100 100.25
10:02:07 200 100.35
10:02:14 300 100.55
10:02:16 100 100.60
10:02:16 300 100.70
10:02:23 200 100.80
;

data want(keep = Time Volume Price dif);
   if _N_ = 1 then do;
      dcl hash h(multidata : "Y");
      h.definekey("t");
      h.definedata("t", "v", "p");
      h.definedone();
      dcl hiter i("h");

      dcl hash hh();
      hh.definekey("t");
      hh.definedata("t", "s");
      hh.definedone();

      do until (z);
         set have end = z;
         h.add(key : time, data : time, data : Volume, data : Price);
         if hh.find(key : Time) ne 0 then s = Volume;
         else                   s + Volume;
         hh.replace(key : Time, data : Time, data : s);
      end;
   end;

   set have;
   t = .; v = .; p = .; s = .;
   aa = constant('big');

   if h.find(key : Time + 10) = 0 then dif = (Price - p) / Price;

   else do;
      do while (i.next() = 0);
         if abs((time + 10) - t) &amp;lt; aa then do;
            mt = t;
            aa = abs((time + 10) - t);
         end;
      end;

      rc = hh.find(key : mt);

      do while (h.do_over(key : mt) = 0);
         pp = sum(pp, divide(v, s) * p);
      end;

      dif = (Price - pp) / Price;
   end;

   format dif 8.4 t mt time8.;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Time      Volume  Price   dif 
10:02:04  100     100.25  -0.0030 
10:02:07  200     100.35  -0.0032 
10:02:14  300     100.55  -0.0025 
10:02:16  100     100.60  -0.0020 
10:02:16  300     100.70  -0.0010 
10:02:23  200     100.80   0.0000 &lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Feb 2021 12:35:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716404#M221407</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-03T12:35:57Z</dc:date>
    </item>
    <item>
      <title>Re: Computing 10-second price difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716412#M221412</link>
      <description>&lt;PRE&gt;data have;
input Time :time8. Volume Price;
format Time time8.;
datalines;
10:02:04 100 100.25
10:02:07 200 100.35
10:02:14 300 100.55
10:02:16 100 100.60
10:02:16 300 100.70
10:02:23 200 100.80
;

proc summary data=have nway;
class Time ;
var Price/weight=Volume;
output out=x(drop=_:) mean=;
run;
proc sql;
create table want as
 select *,
  (price-(select price from x where time between a.time and a.time+10 having time=max(time)))/price as diff
  from x as a;
quit;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Feb 2021 13:04:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716412#M221412</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-02-03T13:04:04Z</dc:date>
    </item>
    <item>
      <title>Re: Computing 10-second price difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716425#M221418</link>
      <description>&lt;P&gt;Many thanks for this. However, it is different from what I want. With this code, in want dataset, I know have only one observation for 10:02:16, which is volume-weighted average. I don't want to lose any observation from the data.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 13:50:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716425#M221418</guid>
      <dc:creator>Khaladdin</dc:creator>
      <dc:date>2021-02-03T13:50:48Z</dc:date>
    </item>
    <item>
      <title>Re: Computing 10-second price difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716428#M221421</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/122878"&gt;@Khaladdin&lt;/a&gt;&amp;nbsp;If you go for the SQL approach, you have to read from have instead of x like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
 select *,
  (price-(select price from x where time between a.time and a.time+10 having time=max(time)))/price as diff format = 8.4
  from have as a;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Feb 2021 13:54:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716428#M221421</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-03T13:54:29Z</dc:date>
    </item>
    <item>
      <title>Re: Computing 10-second price difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716430#M221422</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&amp;nbsp;Cool &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you should read from &lt;STRONG&gt;have&lt;/STRONG&gt; instead of &lt;STRONG&gt;x&lt;/STRONG&gt; though?&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 13:55:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716430#M221422</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-03T13:55:21Z</dc:date>
    </item>
    <item>
      <title>Re: Computing 10-second price difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716443#M221425</link>
      <description>&lt;P&gt;It works well in the existing, however, when I extend the data, I have some problems. Let's say, we have the following data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input Time :time8. Volume Price;&lt;BR /&gt;format Time time8.;&lt;BR /&gt;datalines;&lt;BR /&gt;10:02:04 100 100.25&lt;BR /&gt;10:02:07 200 100.35&lt;BR /&gt;10:02:14 300 100.55&lt;BR /&gt;10:02:16 100 100.60&lt;BR /&gt;10:02:16 300 100.70&lt;BR /&gt;10:02:23 200 100.80&lt;BR /&gt;10:02:35 100 100.90&lt;BR /&gt;10:02:47 300 101.20&lt;BR /&gt;10:02:53 200 101.40&lt;BR /&gt;10:03:11 100 101.60&lt;BR /&gt;10:03:33 300 101.70&lt;BR /&gt;10:03:37 200 101.80&lt;BR /&gt;10:03:45 100 101.60&lt;BR /&gt;10:03:53 300 101.70&lt;BR /&gt;10:04:32 200 102.80&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I use this method, at 10:03:11, I am getting 0. Normally, it should be (101.60 - 101.70)/101.60. Furthermore, at time 10:03:53, I should get (101.70 - 102.80)/101.70. However, I am getting 0 with this code.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 14:00:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716443#M221425</guid>
      <dc:creator>Khaladdin</dc:creator>
      <dc:date>2021-02-03T14:00:23Z</dc:date>
    </item>
    <item>
      <title>Re: Computing 10-second price difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716449#M221427</link>
      <description>&lt;P&gt;Many thanks,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;. It works well. However, now, the only issue is if we do not have any price within 10 seconds, then it returns 0. How can I fix it?&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 14:03:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716449#M221427</guid>
      <dc:creator>Khaladdin</dc:creator>
      <dc:date>2021-02-03T14:03:32Z</dc:date>
    </item>
    <item>
      <title>Re: Computing 10-second price difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716524#M221463</link>
      <description>&lt;P&gt;Ok. So we should not be restricted to 'closest within' 10 seconds, correct?&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 16:24:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716524#M221463</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-03T16:24:53Z</dc:date>
    </item>
    <item>
      <title>Re: Computing 10-second price difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716526#M221464</link>
      <description>&lt;P&gt;Yes.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 16:30:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716526#M221464</guid>
      <dc:creator>Khaladdin</dc:creator>
      <dc:date>2021-02-03T16:30:19Z</dc:date>
    </item>
    <item>
      <title>Re: Computing 10-second price difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716530#M221466</link>
      <description>&lt;P&gt;Ok. Just made a small correction.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See if this works&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Time :time8. Volume Price;
format Time time8.;
datalines;
10:02:04 100 100.25
10:02:07 200 100.35
10:02:14 300 100.55
10:02:16 100 100.60
10:02:16 300 100.70
10:02:23 200 100.80
10:02:35 100 100.90
10:02:47 300 101.20
10:02:53 200 101.40
10:03:11 100 101.60
10:03:33 300 101.70
10:03:37 200 101.80
10:03:45 100 101.60
10:03:53 300 101.70
10:04:32 200 102.80
;

data want(keep = Time Volume Price dif);
   if _N_ = 1 then do;
      dcl hash h(multidata : "Y");
      h.definekey("t");
      h.definedata("t", "v", "p");
      h.definedone();
      dcl hiter i("h");

      dcl hash hh();
      hh.definekey("t");
      hh.definedata("t", "s");
      hh.definedone();

      do until (z);
         set have end = z;
         h.add(key : time, data : time, data : Volume, data : Price);
         if hh.find(key : Time) ne 0 then s = Volume;
         else                   s + Volume;
         hh.replace(key : Time, data : Time, data : s);
      end;
   end;

   set have;
   t = .; v = .; p = .; s = .;
   aa = constant('big');

   if h.find(key : Time + 10) = 0 then dif = (Price - p) / Price;

   else do;
      do while (i.next() = 0);
         if abs((time + 10) - t) &amp;lt; aa and Time ne t then do;
            mt = t;
            aa = abs((time + 10) - t);
         end;
      end;

      rc = hh.find(key : mt);

      do while (h.do_over(key : mt) = 0);
         pp = sum(pp, divide(v, s) * p);
      end;

      dif = (Price - pp) / Price;
   end;

   format dif 8.4 t mt time8.;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Feb 2021 16:33:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716530#M221466</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2021-02-03T16:33:14Z</dc:date>
    </item>
    <item>
      <title>Re: Computing 10-second price difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716533#M221468</link>
      <description>&lt;P&gt;Really sorry. Still small issue. Normally, if there is a value within 10 seconds, then this value should be used first. However, if no value is available within 10 seconds, then the next one should be used (closest from outside 10 seconds).&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 16:41:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716533#M221468</guid>
      <dc:creator>Khaladdin</dc:creator>
      <dc:date>2021-02-03T16:41:38Z</dc:date>
    </item>
    <item>
      <title>Re: Computing 10-second price difference</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716538#M221472</link>
      <description>&lt;P&gt;This code works well. The only issue is it returns 0 if you do not have value within 10 seconds.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 16:54:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Computing-10-second-price-difference/m-p/716538#M221472</guid>
      <dc:creator>Khaladdin</dc:creator>
      <dc:date>2021-02-03T16:54:29Z</dc:date>
    </item>
  </channel>
</rss>

