<?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: Difference between fields with criteria in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-fields-with-criteria/m-p/269867#M53513</link>
    <description>&lt;P&gt;I think you need to show more detail as I am not sure how you are intending to use the "second line". Show the values such as in arithmetic and the expected result for a few lines of the data.&lt;/P&gt;</description>
    <pubDate>Wed, 11 May 2016 20:08:36 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2016-05-11T20:08:36Z</dc:date>
    <item>
      <title>Difference between fields with criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-fields-with-criteria/m-p/269846#M53505</link>
      <description>&lt;P&gt;Good Day All!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am having a bit of a memory block on this one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What i have essentially is a list of users and a a seperate record and timestamp each time they changed thier status in the production system we are using. &amp;nbsp; What i am looking to do in the end is get a total time of all statuses that one of the users had during the day, then skip the very last status for that agent as the next record will have a different agent name... this is the part that is confusing me...&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At the end... i want to add up the statuses to get a total time in each status... so like i can see available time (waiting for an issue)... working (working on an issue) and unavailable (not working or waiting for an issue)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone give me some help in what i need to do to accomplish this? &amp;nbsp;It's straight forward data but i just can't figure out the right combination of code to make it happen.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Dean&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2016 18:45:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-fields-with-criteria/m-p/269846#M53505</guid>
      <dc:creator>D_Z_</dc:creator>
      <dc:date>2016-05-11T18:45:58Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between fields with criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-fields-with-criteria/m-p/269848#M53506</link>
      <description>&lt;P&gt;As long as other variables are not particularly important, the simplest way to compute this would be to calculate based on the ending record, not the starting record.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have;&lt;/P&gt;
&lt;P&gt;by user timestamp;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by user;&lt;/P&gt;
&lt;P&gt;prior_status = lag(status);&lt;/P&gt;
&lt;P&gt;duration = dif(timestamp);&lt;/P&gt;
&lt;P&gt;if first.user=0;&lt;/P&gt;
&lt;P&gt;keep user prior_status duration;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2016 18:54:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-fields-with-criteria/m-p/269848#M53506</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-05-11T18:54:44Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between fields with criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-fields-with-criteria/m-p/269856#M53511</link>
      <description>&lt;P&gt;Thanks for that... it is some awesome code...&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so i have data that looks like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;10MAY16:07:58:14	Available	0:09:44
10MAY16:08:00:53	Unavailable	0:02:39
10MAY16:08:08:20	Available	0:07:28
10MAY16:08:52:18	Work In Progress	0:43:57
10MAY16:08:55:18	Available	0:03:00
10MAY16:09:06:17	Work In Progress	0:10:59
10MAY16:09:36:49	Unavailable	0:30:32
10MAY16:10:25:34	Available	0:48:44
10MAY16:10:55:53	Unavailable	0:30:19
10MAY16:11:10:54	Available	0:15:02
10MAY16:11:15:18	Work In Progress	0:04:23
10MAY16:12:23:02	Unavailable	1:07:44
10MAY16:12:32:34	Available	0:09:32
10MAY16:12:54:10	Work In Progress	0:21:37
10MAY16:13:00:19	Available	0:06:09
10MAY16:13:33:23	Work In Progress	0:33:03
10MAY16:14:23:41	Unavailable	0:50:19
10MAY16:14:34:24	Available	0:10:42
10MAY16:14:38:09	Work In Progress	0:03:45
10MAY16:14:52:01	Available	0:13:53
&lt;/PRE&gt;
&lt;P&gt;So the general idea is that i can sum up available times, unavailable times and work in progress times and get an accurate #... however.... the correct data is one line down if that makes sense.... so on the very first line... the available time i want to be 2:39 instead of the 2nd line for the duration...&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not sure how to do this... but i am going to learn it tonight i have a feeling so i can do this in the future... its really cool. &amp;nbsp;I totally appreciate your help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dean&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2016 19:21:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-fields-with-criteria/m-p/269856#M53511</guid>
      <dc:creator>D_Z_</dc:creator>
      <dc:date>2016-05-11T19:21:09Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between fields with criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-fields-with-criteria/m-p/269867#M53513</link>
      <description>&lt;P&gt;I think you need to show more detail as I am not sure how you are intending to use the "second line". Show the values such as in arithmetic and the expected result for a few lines of the data.&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2016 20:08:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-fields-with-criteria/m-p/269867#M53513</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-05-11T20:08:36Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between fields with criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-fields-with-criteria/m-p/269872#M53515</link>
      <description>&lt;P&gt;So &amp;nbsp;basically what i am doing is starting from a list that shows me user, status, timestamp (that user went into said status)... then i have 3 status catagories &amp;nbsp;(Available, Unavailable, and Work in Progress).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What i want to do is calculate the total sum of each status by user. &amp;nbsp;The first step was to understand how to get the differences between the timestamps and into the correct fields so i can do the calculation afterwards. &amp;nbsp;The the last record&amp;nbsp;for each user should be blank by default because there is not another login time below it for the same user.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now the code above works great... but the data is on the wrong line... the "Is" column as shown below generates the calculation and the "Should Be" is what i am looking for it to read. &amp;nbsp;So in essence, off by one line. and there was data in the very last record on each agent... which i want to keep blank.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Taking the first 2 lines of the table as an example... john was available agt 7:58:14, and then went unavailable at 8:00:53... which means that John was Available for 2.6 minutes.... so in the line one column 3 (Available) i want to see john as available for 2.6 minutes., not 9.7 minutes... but the 2.6 minutes in the "Is" column is on line 2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="505"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="82"&gt;Agent&lt;/TD&gt;
&lt;TD width="118"&gt;Timestamp&lt;/TD&gt;
&lt;TD width="112"&gt;Prior_Status&lt;/TD&gt;
&lt;TD width="64"&gt;Is&lt;/TD&gt;
&lt;TD width="129"&gt;Should Be&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;John Doe&lt;/TD&gt;
&lt;TD&gt;10MAY16:07:58:14&lt;/TD&gt;
&lt;TD&gt;Available&lt;/TD&gt;
&lt;TD&gt;9.7&lt;/TD&gt;
&lt;TD&gt;2.6&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;John Doe&lt;/TD&gt;
&lt;TD&gt;10MAY16:08:00:53&lt;/TD&gt;
&lt;TD&gt;Unavailable&lt;/TD&gt;
&lt;TD&gt;2.6&lt;/TD&gt;
&lt;TD&gt;7.5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;John Doe&lt;/TD&gt;
&lt;TD&gt;10MAY16:08:08:20&lt;/TD&gt;
&lt;TD&gt;Available&lt;/TD&gt;
&lt;TD&gt;7.5&lt;/TD&gt;
&lt;TD&gt;44&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;John Doe&lt;/TD&gt;
&lt;TD&gt;10MAY16:08:52:18&lt;/TD&gt;
&lt;TD&gt;Work In Progress&lt;/TD&gt;
&lt;TD&gt;44&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;John Doe&lt;/TD&gt;
&lt;TD&gt;10MAY16:08:55:18&lt;/TD&gt;
&lt;TD&gt;Available&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;11&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;John Doe&lt;/TD&gt;
&lt;TD&gt;10MAY16:09:06:17&lt;/TD&gt;
&lt;TD&gt;Work In Progress&lt;/TD&gt;
&lt;TD&gt;11&lt;/TD&gt;
&lt;TD&gt;30.5&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;John Doe&lt;/TD&gt;
&lt;TD&gt;10MAY16:09:36:49&lt;/TD&gt;
&lt;TD&gt;Unavailable&lt;/TD&gt;
&lt;TD&gt;30.5&lt;/TD&gt;
&lt;TD&gt;48.7&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;John Doe&lt;/TD&gt;
&lt;TD&gt;10MAY16:10:25:34&lt;/TD&gt;
&lt;TD&gt;Available&lt;/TD&gt;
&lt;TD&gt;48.7&lt;/TD&gt;
&lt;TD&gt;30.3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;John Doe&lt;/TD&gt;
&lt;TD&gt;10MAY16:10:55:53&lt;/TD&gt;
&lt;TD&gt;Unavailable&lt;/TD&gt;
&lt;TD&gt;30.3&lt;/TD&gt;
&lt;TD&gt;15&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;John Doe&lt;/TD&gt;
&lt;TD&gt;10MAY16:11:10:54&lt;/TD&gt;
&lt;TD&gt;Available&lt;/TD&gt;
&lt;TD&gt;15&lt;/TD&gt;
&lt;TD&gt;4.4&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;John Doe&lt;/TD&gt;
&lt;TD&gt;10MAY16:11:15:18&lt;/TD&gt;
&lt;TD&gt;Work In Progress&lt;/TD&gt;
&lt;TD&gt;4.4&lt;/TD&gt;
&lt;TD&gt;67.7&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;John Doe&lt;/TD&gt;
&lt;TD&gt;10MAY16:12:23:02&lt;/TD&gt;
&lt;TD&gt;Unavailable&lt;/TD&gt;
&lt;TD&gt;67.7&lt;/TD&gt;
&lt;TD&gt;--&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2016 20:29:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-fields-with-criteria/m-p/269872#M53515</guid>
      <dc:creator>D_Z_</dc:creator>
      <dc:date>2016-05-11T20:29:23Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between fields with criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-fields-with-criteria/m-p/269876#M53518</link>
      <description>&lt;P&gt;Quick and (very) dirty: Sort the data by agent and descending timestamp; Use &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt;'s code but muliply the dif by -1 then resort the result by agent and timestamp.&lt;/P&gt;
&lt;P&gt;Though I might look for something a bit more elegant if there were millions of records involved. Maybe.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2016 20:51:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-fields-with-criteria/m-p/269876#M53518</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-05-11T20:51:42Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between fields with criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-fields-with-criteria/m-p/269891#M53522</link>
      <description>&lt;P&gt;I think the code I gave you originally should be fine, as long as you focus on the calculated variable named DURATION.&amp;nbsp; The variable named LS might be the one that was already in your data, but should be ignored.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At any rate, if you have additional variables that you want to keep around, here is another way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by id;&lt;/P&gt;
&lt;P&gt;if last.id=0 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; _n_ = _n_ + 1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set have (keep=LS rename=(LS=replacement_LS)) point=_n_;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;else replacement_LS=.;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code moves the duration back to the previous record, using the variable name REPLACEMENT_LS.&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2016 21:05:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-fields-with-criteria/m-p/269891#M53522</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-05-11T21:05:10Z</dc:date>
    </item>
    <item>
      <title>Re: Difference between fields with criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Difference-between-fields-with-criteria/m-p/269898#M53527</link>
      <description>&lt;P&gt;Thanks Astounding! &amp;nbsp;I feel like an idiot though... our original code worked perfectly... i had to go back to the raw data before it was imported to check something and realized that i was wrong... everything was in the right place... I can't believe i missed it...&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Everything is good to go... thanks for the outstanding code... you saved my life and made my VP very happy. &amp;nbsp;She has been after this data for over a year and knew there was a way to do it... just had to reach out.... thanks again!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Dean&lt;/P&gt;</description>
      <pubDate>Wed, 11 May 2016 21:31:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Difference-between-fields-with-criteria/m-p/269898#M53527</guid>
      <dc:creator>D_Z_</dc:creator>
      <dc:date>2016-05-11T21:31:59Z</dc:date>
    </item>
  </channel>
</rss>

