<?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 Datasets different rows value with time calculation. in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Datasets-different-rows-value-with-time-calculation/m-p/83858#M24063</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I having issue by comparing the valid date to I got a dataset n ssd7bdata file format exported a small chuck of the data which looks like the attachment i. now the question I would like to have extra column with the duration in between each catogories such as:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE height="99" style="width: 164px; height: 99px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;9:21&lt;/TD&gt;&lt;TD&gt;XD621&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10:12&lt;/TD&gt;&lt;TD&gt;XD621&lt;/TD&gt;&lt;TD&gt;N&lt;/TD&gt;&lt;TD&gt;0.51&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10:54&lt;/TD&gt;&lt;TD&gt;XD621&lt;/TD&gt;&lt;TD&gt;N&lt;/TD&gt;&lt;TD&gt;0.42&lt;/TD&gt;&lt;TD&gt;N&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11:27&lt;/TD&gt;&lt;TD&gt;XD621&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;TD&gt;0.33&lt;/TD&gt;&lt;TD&gt;N&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then 4th column is the duration in between each row, so the 1st row don have value of previous value will become missing value or .&lt;/P&gt;&lt;P&gt;5th volumn are retain column 3rd for indication total duration of them all,&amp;nbsp; end 4th and 5th column only both rows table value are equal.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I having trouble to select previous or next row of those value and unable to use + or - to get in between time duration.&lt;/P&gt;&lt;P&gt;there are few more calculation need to be done later if these steps are completed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;any idea? and thanks first.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 23 May 2013 07:39:48 GMT</pubDate>
    <dc:creator>Elenatec</dc:creator>
    <dc:date>2013-05-23T07:39:48Z</dc:date>
    <item>
      <title>Datasets different rows value with time calculation.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Datasets-different-rows-value-with-time-calculation/m-p/83858#M24063</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I having issue by comparing the valid date to I got a dataset n ssd7bdata file format exported a small chuck of the data which looks like the attachment i. now the question I would like to have extra column with the duration in between each catogories such as:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE height="99" style="width: 164px; height: 99px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;9:21&lt;/TD&gt;&lt;TD&gt;XD621&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10:12&lt;/TD&gt;&lt;TD&gt;XD621&lt;/TD&gt;&lt;TD&gt;N&lt;/TD&gt;&lt;TD&gt;0.51&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10:54&lt;/TD&gt;&lt;TD&gt;XD621&lt;/TD&gt;&lt;TD&gt;N&lt;/TD&gt;&lt;TD&gt;0.42&lt;/TD&gt;&lt;TD&gt;N&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;11:27&lt;/TD&gt;&lt;TD&gt;XD621&lt;/TD&gt;&lt;TD&gt;Y&lt;/TD&gt;&lt;TD&gt;0.33&lt;/TD&gt;&lt;TD&gt;N&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then 4th column is the duration in between each row, so the 1st row don have value of previous value will become missing value or .&lt;/P&gt;&lt;P&gt;5th volumn are retain column 3rd for indication total duration of them all,&amp;nbsp; end 4th and 5th column only both rows table value are equal.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I having trouble to select previous or next row of those value and unable to use + or - to get in between time duration.&lt;/P&gt;&lt;P&gt;there are few more calculation need to be done later if these steps are completed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;any idea? and thanks first.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 May 2013 07:39:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Datasets-different-rows-value-with-time-calculation/m-p/83858#M24063</guid>
      <dc:creator>Elenatec</dc:creator>
      <dc:date>2013-05-23T07:39:48Z</dc:date>
    </item>
    <item>
      <title>Re: Datasets different rows value with time calculation.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Datasets-different-rows-value-with-time-calculation/m-p/83859#M24064</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;Hi,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;Your data seems like you want to calculate difference between time for each category...But the way you presanted your query, i am not able understand what excatly you want to do...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;Like you wrote 4th and 5th column, but in your sample data there is only 3 columns...So it will be good if you convey your query in meaningful way so that we can solve your query...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;Though, you simply need difference b/w time then please have look at following code...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;data want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; set have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;&amp;nbsp; checkin_time = dif(time);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;Then you can calaulate more based on the value of CHECKIN_TIME variable...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: courier new,courier;"&gt;-Urvish&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 May 2013 12:11:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Datasets-different-rows-value-with-time-calculation/m-p/83859#M24064</guid>
      <dc:creator>UrvishShah</dc:creator>
      <dc:date>2013-05-23T12:11:52Z</dc:date>
    </item>
    <item>
      <title>Re: Datasets different rows value with time calculation.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Datasets-different-rows-value-with-time-calculation/m-p/83860#M24065</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Also, try exploring lag() function which might help u you getting there.&lt;/P&gt;&lt;P&gt;Gud Luk!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 23 May 2013 13:50:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Datasets-different-rows-value-with-time-calculation/m-p/83860#M24065</guid>
      <dc:creator>sascom10</dc:creator>
      <dc:date>2013-05-23T13:50:24Z</dc:date>
    </item>
    <item>
      <title>Re: Datasets different rows value with time calculation.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Datasets-different-rows-value-with-time-calculation/m-p/83861#M24066</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is sample code that calculcates time difference and previous checkin values.&amp;nbsp; You didn't say about across different categories, so I guessed and reset the previous values to missing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The test_table appears to be tab-delimited, so I allowed for that, too.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The key is to write the observation before assigning the current values to the previous value variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data test;&lt;BR /&gt;infile 'c:\temp\test_table.txt'&amp;nbsp; truncover firstobs=2 dlm='09'x;&lt;BR /&gt;input Time :time5. Categories :$5. Checkin :$1. ;&lt;BR /&gt;length prev_category $5;&lt;BR /&gt;retain prev_checkin ' ' prev_time . prev_category ' ';&lt;/P&gt;&lt;P&gt;if categories ne prev_category then do;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* start of new category? */&lt;BR /&gt;&amp;nbsp; prev_time = .;&lt;BR /&gt;&amp;nbsp; prev_checkin = ' ';&lt;BR /&gt;end;&lt;BR /&gt;timediff = time - prev_time;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* calculate difference */&lt;BR /&gt;output;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* write observation */&lt;BR /&gt;prev_checkin = checkin;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* save values for comparison with next row */&lt;BR /&gt;prev_time = time;&lt;BR /&gt;prev_category = categories;&lt;BR /&gt;format time prev_time timediff time5.;&lt;BR /&gt;keep time categories checkin prev_checkin timediff;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc print data=test; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Jan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 May 2013 19:13:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Datasets-different-rows-value-with-time-calculation/m-p/83861#M24066</guid>
      <dc:creator>jwsquillace</dc:creator>
      <dc:date>2013-05-24T19:13:06Z</dc:date>
    </item>
    <item>
      <title>Re: Datasets different rows value with time calculation.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Datasets-different-rows-value-with-time-calculation/m-p/83862#M24067</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thanks guys,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I used lag() fucntion which work fine at the momeny, I still having some issue from the input with alot matchmaking to get the end result, just a quick question about the datasets if the categories always random generated from SAS do I need to sort before create a new datasets because I wanted to calculate the time duration in between each rows with the same categories, does the retain &amp;amp; lag function work the same?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 27 May 2013 09:44:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Datasets-different-rows-value-with-time-calculation/m-p/83862#M24067</guid>
      <dc:creator>Elenatec</dc:creator>
      <dc:date>2013-05-27T09:44:04Z</dc:date>
    </item>
    <item>
      <title>Re: Datasets different rows value with time calculation.</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Datasets-different-rows-value-with-time-calculation/m-p/83863#M24068</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The&amp;nbsp; LAG function works from neighboring observations, so you want to have all the observations for a category together in the input data set.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If the data set is very large, you may find it more efficient to use PROC DATASETS, MODIFY and INDEX CREATE to avoid having to physically rearrange the observations.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cheers,&lt;/P&gt;&lt;P&gt;Jan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 28 May 2013 14:18:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Datasets-different-rows-value-with-time-calculation/m-p/83863#M24068</guid>
      <dc:creator>jwsquillace</dc:creator>
      <dc:date>2013-05-28T14:18:29Z</dc:date>
    </item>
  </channel>
</rss>

