<?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: Time data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Time-data/m-p/265298#M52156</link>
    <description>&lt;P&gt;Here is a better version that takes care of missing intervals:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Generate some random times with some missing values */
data test;
call streaminit(798687);
timedate = '20APR2016:00:00:00'dt;
format timedate datetime17.;
do obs = 1 to 100;
    timedate + rand("Exponential") * '00:03:00't;
    if rand("uniform") &amp;gt; 0.3 
        then value = obs; 
        else call missing(value);
    output;
    end;
run;

/* Assign values to 5 minute intervals. Add missing intervals */
data test2;
set test(rename=value=thisValue);
t = intnx("minute5", timedate, 1, "beginning");
do timedate5 = intnx("minute5", coalesce(lag(t),t), 1) 
        to intnx("minute5", t, -1) 
        by '00:05:00't;
    output;
    end;
timedate5 = t;
value = thisValue;
output;
format timedate5 datetime17.;
drop thisValue t;
run;

/* Keep last value in each interval. Carry values over to fill missing values */
data want;
set test2; by timedate5;
retain lastValue;
if last.timedate5 then do;
    if missing(value) 
        then value = lastValue;
        else lastValue = value;
    output;
    end;
drop lastValue;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 21 Apr 2016 03:00:41 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2016-04-21T03:00:41Z</dc:date>
    <item>
      <title>Time data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-data/m-p/265267#M52146</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have timedate data on the usd/nzd spread, and i am trying to organise it a bit better.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently have 200k observations over a year, that measure price, etc. i already have the following columns already made.&amp;nbsp;if its in the 00.00.00-00.59.59 hour of the day. returning as a 1. and so on. also same for minuties, and 5min intervals.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What i want to is sort the data that it gives me the last quote in a 5 min interval. or if there is no quote in that 5min interval to return the previous 5min intervals quote price.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some 5min intervals have multiple quotes, others have none.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;is there any simple way of re organising my data like this?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2016 22:54:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-data/m-p/265267#M52146</guid>
      <dc:creator>STATSKING</dc:creator>
      <dc:date>2016-04-20T22:54:54Z</dc:date>
    </item>
    <item>
      <title>Re: Time data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-data/m-p/265268#M52147</link>
      <description>&lt;P&gt;Show a few records, dummy values are fine, as long as the key elements show the behavior you need, and what the final result might look like for that example data.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2016 22:57:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-data/m-p/265268#M52147</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-20T22:57:38Z</dc:date>
    </item>
    <item>
      <title>Re: Time data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-data/m-p/265282#M52152</link>
      <description>&lt;P&gt;Here is a simulated example&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
call streaminit(798687);
timedate = '20APR2016:00:00:00'dt;
format timedate datetime17.;
do obs = 1 to 100;
    timedate + rand("Poisson", '00:02:00't);
    if rand("uniform") &amp;gt; 0.3 
        then value = obs; 
        else call missing(value);
    output;
    end;
run;

data test2;
set test;
timedate5 = intnx("minute5", timedate, 1, "beginning");
format timedate5 datetime17.;
run;

data want;
set test2; by timedate5;
retain lastValue;
if last.timedate5 then do;
    if missing(value) 
        then value = lastValue;
        else lastValue = value;
    output;
    end;
drop lastValue;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Apr 2016 02:05:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-data/m-p/265282#M52152</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-04-21T02:05:30Z</dc:date>
    </item>
    <item>
      <title>Re: Time data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Time-data/m-p/265298#M52156</link>
      <description>&lt;P&gt;Here is a better version that takes care of missing intervals:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Generate some random times with some missing values */
data test;
call streaminit(798687);
timedate = '20APR2016:00:00:00'dt;
format timedate datetime17.;
do obs = 1 to 100;
    timedate + rand("Exponential") * '00:03:00't;
    if rand("uniform") &amp;gt; 0.3 
        then value = obs; 
        else call missing(value);
    output;
    end;
run;

/* Assign values to 5 minute intervals. Add missing intervals */
data test2;
set test(rename=value=thisValue);
t = intnx("minute5", timedate, 1, "beginning");
do timedate5 = intnx("minute5", coalesce(lag(t),t), 1) 
        to intnx("minute5", t, -1) 
        by '00:05:00't;
    output;
    end;
timedate5 = t;
value = thisValue;
output;
format timedate5 datetime17.;
drop thisValue t;
run;

/* Keep last value in each interval. Carry values over to fill missing values */
data want;
set test2; by timedate5;
retain lastValue;
if last.timedate5 then do;
    if missing(value) 
        then value = lastValue;
        else lastValue = value;
    output;
    end;
drop lastValue;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 21 Apr 2016 03:00:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Time-data/m-p/265298#M52156</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-04-21T03:00:41Z</dc:date>
    </item>
  </channel>
</rss>

