<?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 difference in values of a single field in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/difference-in-values-of-a-single-field/m-p/54605#M15147</link>
    <description>Hi All,&lt;BR /&gt;
&lt;BR /&gt;
Could you please guide me. I have a field "TIME" and this has values (in ascending order) : &lt;BR /&gt;
&lt;BR /&gt;
10:34:37,&lt;BR /&gt;
10:36:03,&lt;BR /&gt;
10:38:56,&lt;BR /&gt;
10:47:35,&lt;BR /&gt;
10:51:54,&lt;BR /&gt;
10:54:47,&lt;BR /&gt;
11:03:25,&lt;BR /&gt;
&lt;BR /&gt;
I want to find the difference between the suucessive terms and create a field, say, NewDiff which has values 00:00:00,00:01:26 (10:36:03-10:34:37) and so on.&lt;BR /&gt;
&lt;BR /&gt;
Kind Regards,&lt;BR /&gt;
Kritanjli</description>
    <pubDate>Thu, 23 Dec 2010 22:57:26 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2010-12-23T22:57:26Z</dc:date>
    <item>
      <title>difference in values of a single field</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/difference-in-values-of-a-single-field/m-p/54605#M15147</link>
      <description>Hi All,&lt;BR /&gt;
&lt;BR /&gt;
Could you please guide me. I have a field "TIME" and this has values (in ascending order) : &lt;BR /&gt;
&lt;BR /&gt;
10:34:37,&lt;BR /&gt;
10:36:03,&lt;BR /&gt;
10:38:56,&lt;BR /&gt;
10:47:35,&lt;BR /&gt;
10:51:54,&lt;BR /&gt;
10:54:47,&lt;BR /&gt;
11:03:25,&lt;BR /&gt;
&lt;BR /&gt;
I want to find the difference between the suucessive terms and create a field, say, NewDiff which has values 00:00:00,00:01:26 (10:36:03-10:34:37) and so on.&lt;BR /&gt;
&lt;BR /&gt;
Kind Regards,&lt;BR /&gt;
Kritanjli</description>
      <pubDate>Thu, 23 Dec 2010 22:57:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/difference-in-values-of-a-single-field/m-p/54605#M15147</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-12-23T22:57:26Z</dc:date>
    </item>
    <item>
      <title>Re: difference in values of a single field</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/difference-in-values-of-a-single-field/m-p/54606#M15148</link>
      <description>Hi Kritanjli,&lt;BR /&gt;
&lt;BR /&gt;
Let me know if this is what you are after... The lag function is a great function to get the previous value into the PDV (Program Data Vector) to do calculations. Please note that the code below assumes that no time values are missing as then the result is converted to a 0. I have done that so that your first value is 0 rather than missing. Just depends on whether that is a requirement or not.&lt;BR /&gt;
&lt;BR /&gt;
Cheers,&lt;BR /&gt;
Michelle&lt;BR /&gt;
-----------&lt;BR /&gt;
data timeCalculations;&lt;BR /&gt;
	input time : time8.;&lt;BR /&gt;
	format time NewDiff time8.;&lt;BR /&gt;
	NewDiff=time-lag(time);&lt;BR /&gt;
	if NewDiff=. then NewDiff=0;&lt;BR /&gt;
cards;&lt;BR /&gt;
10:34:37&lt;BR /&gt;
10:36:03&lt;BR /&gt;
10:38:56&lt;BR /&gt;
10:47:35&lt;BR /&gt;
10:51:54&lt;BR /&gt;
10:54:47&lt;BR /&gt;
11:03:25&lt;BR /&gt;
;&lt;BR /&gt;
run;</description>
      <pubDate>Fri, 24 Dec 2010 04:05:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/difference-in-values-of-a-single-field/m-p/54606#M15148</guid>
      <dc:creator>MichelleHomes</dc:creator>
      <dc:date>2010-12-24T04:05:58Z</dc:date>
    </item>
    <item>
      <title>Re: difference in values of a single field</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/difference-in-values-of-a-single-field/m-p/54607#M15149</link>
      <description>Hi.&lt;BR /&gt;
Function dif() is identical with time-lag(time)&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data timeCalculations;&lt;BR /&gt;
input time : time8.;&lt;BR /&gt;
format time NewDiff time8.;&lt;BR /&gt;
NewDiff=dif(time);&lt;BR /&gt;
if NewDiff=. then NewDiff=0;&lt;BR /&gt;
cards;&lt;BR /&gt;
10:34:37&lt;BR /&gt;
10:36:03&lt;BR /&gt;
10:38:56&lt;BR /&gt;
10:47:35&lt;BR /&gt;
10:51:54&lt;BR /&gt;
10:54:47&lt;BR /&gt;
11:03:25&lt;BR /&gt;
;&lt;BR /&gt;
run; &lt;BR /&gt;
proc print;run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Fri, 24 Dec 2010 07:10:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/difference-in-values-of-a-single-field/m-p/54607#M15149</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-12-24T07:10:07Z</dc:date>
    </item>
  </channel>
</rss>

