<?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 Select observation at t+5 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Select-observation-at-t-5/m-p/441044#M282574</link>
    <description>&lt;P&gt;I attempted to calculate a formula based on price at different time (&lt;A href="https://i.stack.imgur.com/ikY6q.png" rel="nofollow noreferrer" target="_blank"&gt;&lt;IMG src="https://i.stack.imgur.com/ikY6q.png" border="0" alt="enter image description here" /&gt;&lt;/A&gt;). More specifically,&lt;A href="https://i.stack.imgur.com/P38cB.png" rel="nofollow noreferrer" target="_blank"&gt;&lt;IMG src="https://i.stack.imgur.com/P38cB.png" border="0" alt="enter image description here" /&gt;&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;donates the first price observed at least 5 minutes after the price which is measured.&lt;/P&gt;&lt;P&gt;The following code is used to create a variable that represents&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://i.stack.imgur.com/e9lTn.png" rel="nofollow noreferrer" target="_blank"&gt;&lt;IMG src="https://i.stack.imgur.com/e9lTn.png" border="0" alt="enter image description here" /&gt;&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data WANT;
set  HAVE nobs=nobs;
do _i = _n_ to nobs until(other_date &amp;gt; date_l_);
    set  HAVE(
        rename=(    _ric=other_ric
                    date_l_= other_date 
                    price = other_price 
                    new_time = other_time)
        keep=_ric date_l_ price int1min new_time) 
        point=_i;
    if other_ric=_ric and new_time &amp;gt; new_time+300 and other_date = date_l_ then do;
        new_price = other_price;
        leave;
        end;
    end;
drop other_: ;
run;    &lt;/PRE&gt;&lt;P&gt;However, the code did not work correctly at all time. As shown in the pic, the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE&gt;new_price&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;is correct in green rectangle but is incorrect in red rectangle. Could anyone help me to solve this problem? I attached a sample of data as well.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://i.stack.imgur.com/qPym5.png" border="0" alt="enter image description here" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 28 Feb 2018 21:58:09 GMT</pubDate>
    <dc:creator>Neal0801</dc:creator>
    <dc:date>2018-02-28T21:58:09Z</dc:date>
    <item>
      <title>Select observation at t+5</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-observation-at-t-5/m-p/441044#M282574</link>
      <description>&lt;P&gt;I attempted to calculate a formula based on price at different time (&lt;A href="https://i.stack.imgur.com/ikY6q.png" rel="nofollow noreferrer" target="_blank"&gt;&lt;IMG src="https://i.stack.imgur.com/ikY6q.png" border="0" alt="enter image description here" /&gt;&lt;/A&gt;). More specifically,&lt;A href="https://i.stack.imgur.com/P38cB.png" rel="nofollow noreferrer" target="_blank"&gt;&lt;IMG src="https://i.stack.imgur.com/P38cB.png" border="0" alt="enter image description here" /&gt;&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;donates the first price observed at least 5 minutes after the price which is measured.&lt;/P&gt;&lt;P&gt;The following code is used to create a variable that represents&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://i.stack.imgur.com/e9lTn.png" rel="nofollow noreferrer" target="_blank"&gt;&lt;IMG src="https://i.stack.imgur.com/e9lTn.png" border="0" alt="enter image description here" /&gt;&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data WANT;
set  HAVE nobs=nobs;
do _i = _n_ to nobs until(other_date &amp;gt; date_l_);
    set  HAVE(
        rename=(    _ric=other_ric
                    date_l_= other_date 
                    price = other_price 
                    new_time = other_time)
        keep=_ric date_l_ price int1min new_time) 
        point=_i;
    if other_ric=_ric and new_time &amp;gt; new_time+300 and other_date = date_l_ then do;
        new_price = other_price;
        leave;
        end;
    end;
drop other_: ;
run;    &lt;/PRE&gt;&lt;P&gt;However, the code did not work correctly at all time. As shown in the pic, the&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE&gt;new_price&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;is correct in green rectangle but is incorrect in red rectangle. Could anyone help me to solve this problem? I attached a sample of data as well.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://i.stack.imgur.com/qPym5.png" border="0" alt="enter image description here" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2018 21:58:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-observation-at-t-5/m-p/441044#M282574</guid>
      <dc:creator>Neal0801</dc:creator>
      <dc:date>2018-02-28T21:58:09Z</dc:date>
    </item>
    <item>
      <title>Re: Select observation at t+5</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Select-observation-at-t-5/m-p/441046#M282575</link>
      <description>&lt;P&gt;Shouldn't it be&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if other_ric=_ric and &lt;STRONG&gt;&lt;FONT color="#ff6600"&gt;other&lt;/FONT&gt;&lt;/STRONG&gt;_time &amp;gt; new_time+300 and other_date = date_l_ then do;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Feb 2018 22:08:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Select-observation-at-t-5/m-p/441046#M282575</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-02-28T22:08:10Z</dc:date>
    </item>
  </channel>
</rss>

