<?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: calculating a time difference in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/calculating-a-time-difference/m-p/478783#M31064</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*sort data for by group processing;
proc sort data=sashelp.stocks out=stocks1; by stock date;

data stocks2;
set stocks1;
by stock date;

*get previous value;
prev_open = lag(open);
*if first record for the stock group, set to missing to avoid using 
previous stocks value;
if first.stock then call missing(prev_open);

*calculate difference when not missing;
if not missing(prev_open) then difference = open - prev_open;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 17 Jul 2018 19:22:41 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-07-17T19:22:41Z</dc:date>
    <item>
      <title>calculating a time difference</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/calculating-a-time-difference/m-p/478763#M31056</link>
      <description>&lt;P&gt;Hey Guys!&lt;BR /&gt;&lt;BR /&gt;sorry for my english but I hope you&amp;nbsp; understand and could help me.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I want to get the following information:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The time betweeen the timestamps "e"&amp;nbsp; in seconds from one object with an unique "ipid".&lt;/P&gt;&lt;P&gt;Please see my attachement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried with DATADIFF and LAG:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;SELECT DATEDIFF (second, ptime, e), q.*&lt;BR /&gt;FROM (SELECT *,&lt;BR /&gt;LAG(e) OVER (PARTITION BY ipid ORDER BY e) ptime&lt;BR /&gt;FROM Table ) q&lt;BR /&gt;WHERE ptime IS NOT NULL&lt;BR /&gt;&lt;BR /&gt;But: "The LAG function is not supported in PROC SQL, it is only valid within the DATA step."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You have any other idea?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!!!&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 18:46:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/calculating-a-time-difference/m-p/478763#M31056</guid>
      <dc:creator>Hans_Mahler</dc:creator>
      <dc:date>2018-07-17T18:46:52Z</dc:date>
    </item>
    <item>
      <title>Re: calculating a time difference</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/calculating-a-time-difference/m-p/478764#M31057</link>
      <description>&lt;P&gt;You could do the calculations in a data step instead of PROC SQL. Then the LAG function would work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 18:50:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/calculating-a-time-difference/m-p/478764#M31057</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-07-17T18:50:53Z</dc:date>
    </item>
    <item>
      <title>Re: calculating a time difference</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/calculating-a-time-difference/m-p/478769#M31059</link>
      <description>&lt;P&gt;OVER BY and PARTITION are also not supported so your best best is to switch to a data step.&lt;/P&gt;
&lt;P&gt;You can also use the DIF() function directly instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/221553"&gt;@Hans_Mahler&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;STRIKE&gt;Hey Guys!&lt;/STRIKE&gt;&lt;BR /&gt;&lt;BR /&gt;sorry for my english but I hope you&amp;nbsp; understand and could help me.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;I want to get the following information:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The time betweeen the timestamps "e"&amp;nbsp; in seconds from one object with an unique "ipid".&lt;/P&gt;
&lt;P&gt;Please see my attachement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried with DATADIFF and LAG:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;SELECT DATEDIFF (second, ptime, e), q.*&lt;BR /&gt;FROM (SELECT *,&lt;BR /&gt;LAG(e) OVER (PARTITION BY ipid ORDER BY e) ptime&lt;BR /&gt;FROM Table ) q&lt;BR /&gt;WHERE ptime IS NOT NULL&lt;BR /&gt;&lt;BR /&gt;But: "The LAG function is not supported in PROC SQL, it is only valid within the DATA step."&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have any other idea?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!!!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 19:05:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/calculating-a-time-difference/m-p/478769#M31059</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-17T19:05:05Z</dc:date>
    </item>
    <item>
      <title>Re: calculating a time difference</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/calculating-a-time-difference/m-p/478775#M31061</link>
      <description>sorry but i dont know how this works in DATA step? you mean i sort my data and then..?</description>
      <pubDate>Tue, 17 Jul 2018 19:12:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/calculating-a-time-difference/m-p/478775#M31061</guid>
      <dc:creator>Hans_Mahler</dc:creator>
      <dc:date>2018-07-17T19:12:19Z</dc:date>
    </item>
    <item>
      <title>Re: calculating a time difference</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/calculating-a-time-difference/m-p/478783#M31064</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*sort data for by group processing;
proc sort data=sashelp.stocks out=stocks1; by stock date;

data stocks2;
set stocks1;
by stock date;

*get previous value;
prev_open = lag(open);
*if first record for the stock group, set to missing to avoid using 
previous stocks value;
if first.stock then call missing(prev_open);

*calculate difference when not missing;
if not missing(prev_open) then difference = open - prev_open;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Jul 2018 19:22:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/calculating-a-time-difference/m-p/478783#M31064</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-17T19:22:41Z</dc:date>
    </item>
  </channel>
</rss>

