<?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: How to retain a value if we have a big messy data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-a-value-if-we-have-a-big-messy-data/m-p/448595#M112855</link>
    <description>&lt;P&gt;Yes, you are absolutely right. First we need to define "Close". Honestly I am also confuse. Actually this is someone else projects who left and now I am responsible to continue working on it. It is an ongoing project and my supervisor wants me to continue working on it the same way previous person was doing.&amp;nbsp;She used STATA for analysis, and I have no background knowledge of STATA. I got most of her work but only this part of coding is difficult to understand. Below are STATA codes, it might help you. What I am understanding that data is sorted at id, ts_ser, and ts and then notecount variable has retained based on if ((ts_ser=lag(ts_ser) or ((ts_ser-ts_ser) le&amp;nbsp; 2 min))) or (ts=lag(ts) or ((ts-ts) le 2 min))). In codes below, I think 2000= 2minutes. I am hoping I am making some sense to you.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;set more off&lt;BR /&gt;&amp;nbsp;local i=1&lt;BR /&gt;&amp;nbsp;while `i'&amp;lt;7 {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;while inlist(`i',1,3,5) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;local j=1&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;sort&amp;nbsp;id ts_ser ts&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;while `j'&amp;lt;100 {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;replace notecount=notecount[_n+1] if notecount==. &amp;amp; notecount[_n+1]!=. &amp;amp; id==id[_n+1] &amp;amp; ///&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(ts_ser==ts_ser[_n+1] | abs(ts_ser-ts_ser[_n+1])&amp;lt;=2000 | ts==ts[_n+1] | abs(ts-ts[_n+1])&amp;lt;=2000)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;replace notecount=notecount[_n-1] if notecount==. &amp;amp; notecount[_n-1]!=. &amp;amp; id==id[_n-1] &amp;amp; ///&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(ts_ser==ts_ser[_n-1] | abs(ts_ser-ts_ser[_n-1])&amp;lt;=2000 | ts==ts[_n-1] | abs(ts-ts[_n-1])&amp;lt;=2000)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;local j=`j'+1&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;local i=`i'+1&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR /&gt;&amp;nbsp;&amp;nbsp;while inlist(`i',2,4,6) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;local j=1&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;sort&amp;nbsp;id ts ts_ser&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;while `j'&amp;lt;100 {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;replace notecount=notecount[_n+1] if notecount==. &amp;amp; notecount[_n+1]!=. &amp;amp; id==id[_n+1] &amp;amp; ///&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(ts_ser==ts_ser[_n+1] | abs(ts_ser-ts_ser[_n+1])&amp;lt;=2000 | ts==ts[_n+1] | abs(ts-ts[_n+1])&amp;lt;=2000)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;replace notecount=notecount[_n-1] if notecount==. &amp;amp; notecount[_n-1]!=. &amp;amp; id==id[_n-1] &amp;amp; ///&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(ts_ser==ts_ser[_n-1] | abs(ts_ser-ts_ser[_n-1])&amp;lt;=2000 | ts==ts[_n-1] | abs(ts-ts[_n-1])&amp;lt;=2000)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;local j=`j'+1&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;local i=`i'+1&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR /&gt;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 26 Mar 2018 11:27:08 GMT</pubDate>
    <dc:creator>AMFR</dc:creator>
    <dc:date>2018-03-26T11:27:08Z</dc:date>
    <item>
      <title>How to retain a value if we have a big messy data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-a-value-if-we-have-a-big-messy-data/m-p/448156#M112705</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is a very small part of my big messy data&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data temp;&lt;BR /&gt;&amp;nbsp;input ID Action $ TS_SER TS Verify Notecount;&lt;BR /&gt;&amp;nbsp;informat TS_SER datetime14. TS&amp;nbsp;datetime14.;&lt;BR /&gt;&amp;nbsp;format TS_SER &amp;nbsp;datetime14.&amp;nbsp;TS datetime14.;&lt;BR /&gt;&amp;nbsp;datalines;&lt;/P&gt;&lt;P&gt;252670 Sign 13DEC17:11:05 13DEC17:11:14 . .&lt;BR /&gt;252670 Perform 13DEC17:11:05 13DEC17:11:14 . .&lt;BR /&gt;252670 Verify 13DEC17:11:05 13DEC17:11:14&amp;nbsp; 1 1&lt;BR /&gt;252670 Sign 13DEC17:15:27 13DEC17:15:41 . .&lt;BR /&gt;252670 Perform 13DEC17:15:27 13DEC17:15:41 . .&lt;BR /&gt;252670 Verify 13DEC17:15:27 13DEC17:15:41 1 2&lt;BR /&gt;252670 Sign 13DEC17:16:28 13DEC17:16:30 . .&lt;BR /&gt;252670 Perform 13DEC17:16:28 13DEC17:16:30 . .&lt;BR /&gt;252670 Verify 13DEC17:16:28 13DEC17:16:30 1 3&lt;BR /&gt;252670 Sign 13DEC17:16:29 13DEC17:16:30 . .&lt;BR /&gt;252670 Modify 13DEC17:16:29 13DEC17:16:30 . .&lt;BR /&gt;252670 Perform 14DEC17:07:32 14DEC17:07:34 . .&lt;BR /&gt;252670 Verify 14DEC17:07:32 14DEC17:07:34 1 4&lt;BR /&gt;252670 Sign 14DEC17:07:32 14DEC17:07:34 . .&lt;BR /&gt;252670 Perform 14DEC17:09:15 14DEC17:09:15 . .&lt;BR /&gt;252670 Verify 14DEC17:09:15 14DEC17:09:15 1 5&lt;BR /&gt;252670 Sign 14DEC17:09:15 14DEC17:09:15 . .&lt;BR /&gt;252670 Perform 14DEC17:14:18 14DEC17:16:29 . .&lt;BR /&gt;252670 Verify 14DEC17:14:18 14DEC17:16:29 1 6&lt;BR /&gt;252670 Sign 14DEC17:14:18 14DEC17:14:18 . .&lt;BR /&gt;252670 Sign 14DEC17:14:18 14DEC17:16:29 . .&lt;BR /&gt;252670 Sign 14DEC17:16:13 14DEC17:16:17 . .&lt;BR /&gt;252670 Perform 14DEC17:16:13 14DEC17:16:17 . .&lt;BR /&gt;252670 Verify 14DEC17:16:13 14DEC17:16:17 1 7&lt;BR /&gt;252670 Modify 14DEC17:16:29 14DEC17:16:29 . .&lt;BR /&gt;252670 Perform 14DEC17:16:29 14DEC17:16:29 . .&lt;BR /&gt;252670 Sign 14DEC17:16:29 14DEC17:16:29 . .&lt;BR /&gt;252670 Perform 14DEC17:19:12 14DEC17:19:15 . .&lt;BR /&gt;252670 Verify 14DEC17:19:12 14DEC17:19:15 1 8&lt;BR /&gt;252670 Sign 14DEC17:19:12 14DEC17:19:15 . .&lt;BR /&gt;252670 Perform 15DEC17:15:27 15DEC17:15:27 . .&lt;BR /&gt;252670 Verify 15DEC17:15:27 15DEC17:15:27 1 9&lt;BR /&gt;252670 Sign 15DEC17:15:27 15DEC17:15:27 . .&lt;BR /&gt;252670 Sign 16DEC17:10:38 16DEC17:10:38 . .&lt;BR /&gt;252670 Perform 16DEC17:10:38 16DEC17:10:38 . .&lt;BR /&gt;252670 Verify 16DEC17:10:38 16DEC17:10:38 1 10&lt;BR /&gt;318672 Sign 13OCT17:20:32 14OCT17:10:11 . .&lt;BR /&gt;318672 Modify 13OCT17:20:36 14OCT17:10:11&amp;nbsp; . .&lt;BR /&gt;318672 Modify 13OCT17:20:37 14OCT17:10:11 . .&lt;BR /&gt;318672 Modify 13OCT17:20:40 14OCT17:10:11 . .&lt;BR /&gt;318672 Modify 13OCT17:20:44 14OCT17:10:11 . .&lt;BR /&gt;318672 Modify 13OCT17:20:46 14OCT17:10:11 . .&lt;BR /&gt;318672 Modify 13OCT17:23:03 14OCT17:10:11 . .&lt;BR /&gt;318672 Sign 13OCT17:23:03 14OCT17:10:11 . .&lt;BR /&gt;318672 Sign 13OCT17:23:04 13OCT17:23:04 . .&lt;BR /&gt;318672 Verify 14OCT17:10:11 14OCT17:10:11 1 1&lt;BR /&gt;318672 Sign 14OCT17:10:11 14OCT17:10:11 . .&lt;BR /&gt;318672 Sign 14OCT17:10:26 14OCT17:10:52 . .&lt;BR /&gt;318672 Perform 14OCT17:10:26 14OCT17:14:09 . .&lt;BR /&gt;318672 Modify 14OCT17:10:52 14OCT17:14:09 . .&lt;BR /&gt;318672 Sign 14OCT17:10:54 14OCT17:10:54 . .&lt;BR /&gt;318672 Sign 14OCT17:10:54 14OCT17:14:09 . .&lt;BR /&gt;318672 Modify 14OCT17:10:54 14OCT17:14:09 . .&lt;BR /&gt;318672 Verify 14OCT17:10:54 14OCT17:14:09 1 2&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to retain value of notecount so my clean data would look like this (as below). I need to retain variable notecount &amp;nbsp;based on TS_SER and TS.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data temp1;&lt;BR /&gt;&amp;nbsp;input ID Action $ TS_SER TS Verify Notecount;&lt;BR /&gt;&amp;nbsp; informat&amp;nbsp;TS_SER datetime14.&amp;nbsp;TS datetime14.;&lt;BR /&gt;&amp;nbsp;format&amp;nbsp;TS_SER datetime14.&amp;nbsp;TS datetime14.;&lt;BR /&gt;&amp;nbsp;datalines;&lt;/P&gt;&lt;P&gt;252670 Sign 13DEC17:11:05 13DEC17:11:14 . 1&lt;BR /&gt;252670 Perform 13DEC17:11:05 13DEC17:11:14 . 1&lt;BR /&gt;252670 Verify 13DEC17:11:05 13DEC17:11:14&amp;nbsp; 1 1&lt;BR /&gt;252670 Sign 13DEC17:15:27 13DEC17:15:41 . 2&lt;BR /&gt;252670 Perform 13DEC17:15:27 13DEC17:15:41 . 2&lt;BR /&gt;252670 Verify 13DEC17:15:27 13DEC17:15:41 1 2&lt;BR /&gt;252670 Sign 13DEC17:16:28 13DEC17:16:30 . 3&lt;BR /&gt;252670 Perform 13DEC17:16:28 13DEC17:16:30 . 3&lt;BR /&gt;252670 Verify 13DEC17:16:28 13DEC17:16:30 1 3&lt;BR /&gt;252670 Sign 13DEC17:16:29 13DEC17:16:30 . 3&lt;BR /&gt;252670 Modify 13DEC17:16:29 13DEC17:16:30 . 3&lt;BR /&gt;252670 Perform 14DEC17:07:32 14DEC17:07:34 . 4&lt;BR /&gt;252670 Verify 14DEC17:07:32 14DEC17:07:34 1 4&lt;BR /&gt;252670 Sign 14DEC17:07:32 14DEC17:07:34 . 4&lt;BR /&gt;252670 Perform 14DEC17:09:15 14DEC17:09:15 . 5&lt;BR /&gt;252670 Verify 14DEC17:09:15 14DEC17:09:15 1 5&lt;BR /&gt;252670 Sign 14DEC17:09:15 14DEC17:09:15 . 5&lt;BR /&gt;252670 Perform 14DEC17:14:18 14DEC17:16:29 . 6&lt;BR /&gt;252670 Verify 14DEC17:14:18 14DEC17:16:29 1 6&lt;BR /&gt;252670 Sign 14DEC17:14:18 14DEC17:14:18 . 6&lt;BR /&gt;252670 Sign 14DEC17:14:18 14DEC17:16:29 . 6&lt;BR /&gt;252670 Modify 14DEC17:16:29 14DEC17:16:29 . 6&lt;BR /&gt;252670 Perform 14DEC17:16:29 14DEC17:16:29 . 6&lt;BR /&gt;252670 Sign 14DEC17:16:29 14DEC17:16:29 . 6&lt;BR /&gt;252670 Sign 14DEC17:16:13 14DEC17:16:17 . 7&lt;BR /&gt;252670 Perform 14DEC17:16:13 14DEC17:16:17 . 7&lt;BR /&gt;252670 Verify 14DEC17:16:13 14DEC17:16:17 1 7&lt;BR /&gt;252670 Perform 14DEC17:19:12 14DEC17:19:15 . 8&lt;BR /&gt;252670 Verify 14DEC17:19:12 14DEC17:19:15 1 8&lt;BR /&gt;252670 Sign 14DEC17:19:12 14DEC17:19:15 . 8&lt;BR /&gt;252670 Perform 15DEC17:15:27 15DEC17:15:27 . 9&lt;BR /&gt;252670 Verify 15DEC17:15:27 15DEC17:15:27 1 9&lt;BR /&gt;252670 Sign 15DEC17:15:27 15DEC17:15:27 . 9&lt;BR /&gt;252670 Sign 16DEC17:10:38 16DEC17:10:38 . 10&lt;BR /&gt;252670 Perform 16DEC17:10:38 16DEC17:10:38 . 10&lt;BR /&gt;252670 Verify 16DEC17:10:38 16DEC17:10:38 1 10&lt;BR /&gt;318672 Sign 13OCT17:20:32 14OCT17:10:11 . 1&lt;BR /&gt;318672 Modify 13OCT17:20:36 14OCT17:10:11&amp;nbsp; . 1&lt;BR /&gt;318672 Modify 13OCT17:20:37 14OCT17:10:11 . 1&lt;BR /&gt;318672 Modify 13OCT17:20:40 14OCT17:10:11 . 1&lt;BR /&gt;318672 Modify 13OCT17:20:44 14OCT17:10:11 . 1&lt;BR /&gt;318672 Modify 13OCT17:20:46 14OCT17:10:11 . 1&lt;BR /&gt;318672 Modify 13OCT17:23:03 14OCT17:10:11 . 1&lt;BR /&gt;318672 Sign 13OCT17:23:03 14OCT17:10:11 . 1&lt;BR /&gt;318672 Sign 13OCT17:23:04 13OCT17:23:04 . 1&lt;BR /&gt;318672 Verify 14OCT17:10:11 14OCT17:10:11 1 1&lt;BR /&gt;318672 Sign 14OCT17:10:11 14OCT17:10:11 . 1&lt;BR /&gt;318672 Sign 14OCT17:10:26 14OCT17:10:52 . 2&lt;BR /&gt;318672 Perform 14OCT17:10:26 14OCT17:14:09 . 2&lt;BR /&gt;318672 Modify 14OCT17:10:52 14OCT17:14:09 . 2&lt;BR /&gt;318672 Sign 14OCT17:10:54 14OCT17:10:54 . 2&lt;BR /&gt;318672 Sign 14OCT17:10:54 14OCT17:14:09 . 2&lt;BR /&gt;318672 Modify 14OCT17:10:54 14OCT17:14:09 . 2&lt;BR /&gt;318672 Verify 14OCT17:10:54 14OCT17:14:09 1 2&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc print data=work.temp1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you all.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Mar 2018 13:53:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-a-value-if-we-have-a-big-messy-data/m-p/448156#M112705</guid>
      <dc:creator>AMFR</dc:creator>
      <dc:date>2018-03-23T13:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain a value if we have a big messy data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-a-value-if-we-have-a-big-messy-data/m-p/448166#M112713</link>
      <description>&lt;P&gt;Here could give you a start.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data temp;
 input ID Action $ TS_SER TS Verify Notecount;
 informat TS_SER datetime14. TS datetime14.;
 format TS_SER  datetime14. TS datetime14.;
 datalines;
252670 Sign 13DEC17:11:05 13DEC17:11:14 . .
252670 Perform 13DEC17:11:05 13DEC17:11:14 . .
252670 Verify 13DEC17:11:05 13DEC17:11:14  1 1
252670 Sign 13DEC17:15:27 13DEC17:15:41 . .
252670 Perform 13DEC17:15:27 13DEC17:15:41 . .
252670 Verify 13DEC17:15:27 13DEC17:15:41 1 2
252670 Sign 13DEC17:16:28 13DEC17:16:30 . .
252670 Perform 13DEC17:16:28 13DEC17:16:30 . .
252670 Verify 13DEC17:16:28 13DEC17:16:30 1 3
252670 Sign 13DEC17:16:29 13DEC17:16:30 . .
252670 Modify 13DEC17:16:29 13DEC17:16:30 . .
252670 Perform 14DEC17:07:32 14DEC17:07:34 . .
252670 Verify 14DEC17:07:32 14DEC17:07:34 1 4
252670 Sign 14DEC17:07:32 14DEC17:07:34 . .
252670 Perform 14DEC17:09:15 14DEC17:09:15 . .
252670 Verify 14DEC17:09:15 14DEC17:09:15 1 5
252670 Sign 14DEC17:09:15 14DEC17:09:15 . .
252670 Perform 14DEC17:14:18 14DEC17:16:29 . .
252670 Verify 14DEC17:14:18 14DEC17:16:29 1 6
252670 Sign 14DEC17:14:18 14DEC17:14:18 . .
252670 Sign 14DEC17:14:18 14DEC17:16:29 . .
252670 Sign 14DEC17:16:13 14DEC17:16:17 . .
252670 Perform 14DEC17:16:13 14DEC17:16:17 . .
252670 Verify 14DEC17:16:13 14DEC17:16:17 1 7
252670 Modify 14DEC17:16:29 14DEC17:16:29 . .
252670 Perform 14DEC17:16:29 14DEC17:16:29 . .
252670 Sign 14DEC17:16:29 14DEC17:16:29 . .
252670 Perform 14DEC17:19:12 14DEC17:19:15 . .
252670 Verify 14DEC17:19:12 14DEC17:19:15 1 8
252670 Sign 14DEC17:19:12 14DEC17:19:15 . .
252670 Perform 15DEC17:15:27 15DEC17:15:27 . .
252670 Verify 15DEC17:15:27 15DEC17:15:27 1 9
252670 Sign 15DEC17:15:27 15DEC17:15:27 . .
252670 Sign 16DEC17:10:38 16DEC17:10:38 . .
252670 Perform 16DEC17:10:38 16DEC17:10:38 . .
252670 Verify 16DEC17:10:38 16DEC17:10:38 1 10
318672 Sign 13OCT17:20:32 14OCT17:10:11 . .
318672 Modify 13OCT17:20:36 14OCT17:10:11  . .
318672 Modify 13OCT17:20:37 14OCT17:10:11 . .
318672 Modify 13OCT17:20:40 14OCT17:10:11 . .
318672 Modify 13OCT17:20:44 14OCT17:10:11 . .
318672 Modify 13OCT17:20:46 14OCT17:10:11 . .
318672 Modify 13OCT17:23:03 14OCT17:10:11 . .
318672 Sign 13OCT17:23:03 14OCT17:10:11 . .
318672 Sign 13OCT17:23:04 13OCT17:23:04 . .
318672 Verify 14OCT17:10:11 14OCT17:10:11 1 1
318672 Sign 14OCT17:10:11 14OCT17:10:11 . .
318672 Sign 14OCT17:10:26 14OCT17:10:52 . .
318672 Perform 14OCT17:10:26 14OCT17:14:09 . .
318672 Modify 14OCT17:10:52 14OCT17:14:09 . .
318672 Sign 14OCT17:10:54 14OCT17:10:54 . .
318672 Sign 14OCT17:10:54 14OCT17:14:09 . .
318672 Modify 14OCT17:10:54 14OCT17:14:09 . .
318672 Verify 14OCT17:10:54 14OCT17:14:09 1 2
;
run;
proc sort data=temp;
by  id  TS;
run;
data want;
 merge temp 
 temp(keep=id TS_SER TS Notecount rename=(Notecount=want)
 where=(want is not missing));
 by id  TS;
run;
proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Mar 2018 14:25:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-a-value-if-we-have-a-big-messy-data/m-p/448166#M112713</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-03-23T14:25:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain a value if we have a big messy data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-a-value-if-we-have-a-big-messy-data/m-p/448170#M112716</link>
      <description>&lt;P&gt;Where from do you get the "2" for ID=318672 and TS=14OCT17:10:52?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Other than that, try&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select
  ID, Action, TS_SER, TS, Verify,
  max(notecount) as notecount
from temp
group by id, ts
order by id, ts_ser
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Mar 2018 14:36:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-a-value-if-we-have-a-big-messy-data/m-p/448170#M112716</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-23T14:36:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain a value if we have a big messy data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-a-value-if-we-have-a-big-messy-data/m-p/448194#M112725</link>
      <description>&lt;P&gt;it would be 2 because if you look at the Ser_Ts when it got verified.14OCT17:10:54, both timestamps are very close. Your codes are very helpful but not giving me desired results. I will try to work around through your codes&lt;/P&gt;</description>
      <pubDate>Fri, 23 Mar 2018 15:31:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-a-value-if-we-have-a-big-messy-data/m-p/448194#M112725</guid>
      <dc:creator>AMFR</dc:creator>
      <dc:date>2018-03-23T15:31:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain a value if we have a big messy data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-a-value-if-we-have-a-big-messy-data/m-p/448199#M112730</link>
      <description>&lt;P&gt;Thank you very much for your help. I am not getting desired results but I can try to work around. Please let me know if you find any other solution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Mar 2018 15:33:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-a-value-if-we-have-a-big-messy-data/m-p/448199#M112730</guid>
      <dc:creator>AMFR</dc:creator>
      <dc:date>2018-03-23T15:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain a value if we have a big messy data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-a-value-if-we-have-a-big-messy-data/m-p/448226#M112749</link>
      <description>&lt;P&gt;Define "close". When do timestamps have to be considered as one, and when are they separate?&lt;/P&gt;</description>
      <pubDate>Fri, 23 Mar 2018 16:31:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-a-value-if-we-have-a-big-messy-data/m-p/448226#M112749</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-23T16:31:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain a value if we have a big messy data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-a-value-if-we-have-a-big-messy-data/m-p/448595#M112855</link>
      <description>&lt;P&gt;Yes, you are absolutely right. First we need to define "Close". Honestly I am also confuse. Actually this is someone else projects who left and now I am responsible to continue working on it. It is an ongoing project and my supervisor wants me to continue working on it the same way previous person was doing.&amp;nbsp;She used STATA for analysis, and I have no background knowledge of STATA. I got most of her work but only this part of coding is difficult to understand. Below are STATA codes, it might help you. What I am understanding that data is sorted at id, ts_ser, and ts and then notecount variable has retained based on if ((ts_ser=lag(ts_ser) or ((ts_ser-ts_ser) le&amp;nbsp; 2 min))) or (ts=lag(ts) or ((ts-ts) le 2 min))). In codes below, I think 2000= 2minutes. I am hoping I am making some sense to you.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;set more off&lt;BR /&gt;&amp;nbsp;local i=1&lt;BR /&gt;&amp;nbsp;while `i'&amp;lt;7 {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;while inlist(`i',1,3,5) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;local j=1&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;sort&amp;nbsp;id ts_ser ts&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;while `j'&amp;lt;100 {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;replace notecount=notecount[_n+1] if notecount==. &amp;amp; notecount[_n+1]!=. &amp;amp; id==id[_n+1] &amp;amp; ///&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(ts_ser==ts_ser[_n+1] | abs(ts_ser-ts_ser[_n+1])&amp;lt;=2000 | ts==ts[_n+1] | abs(ts-ts[_n+1])&amp;lt;=2000)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;replace notecount=notecount[_n-1] if notecount==. &amp;amp; notecount[_n-1]!=. &amp;amp; id==id[_n-1] &amp;amp; ///&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(ts_ser==ts_ser[_n-1] | abs(ts_ser-ts_ser[_n-1])&amp;lt;=2000 | ts==ts[_n-1] | abs(ts-ts[_n-1])&amp;lt;=2000)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;local j=`j'+1&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;local i=`i'+1&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR /&gt;&amp;nbsp;&amp;nbsp;while inlist(`i',2,4,6) {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;local j=1&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;sort&amp;nbsp;id ts ts_ser&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;while `j'&amp;lt;100 {&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;replace notecount=notecount[_n+1] if notecount==. &amp;amp; notecount[_n+1]!=. &amp;amp; id==id[_n+1] &amp;amp; ///&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(ts_ser==ts_ser[_n+1] | abs(ts_ser-ts_ser[_n+1])&amp;lt;=2000 | ts==ts[_n+1] | abs(ts-ts[_n+1])&amp;lt;=2000)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;replace notecount=notecount[_n-1] if notecount==. &amp;amp; notecount[_n-1]!=. &amp;amp; id==id[_n-1] &amp;amp; ///&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(ts_ser==ts_ser[_n-1] | abs(ts_ser-ts_ser[_n-1])&amp;lt;=2000 | ts==ts[_n-1] | abs(ts-ts[_n-1])&amp;lt;=2000)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;local j=`j'+1&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;local i=`i'+1&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;BR /&gt;&amp;nbsp;&amp;nbsp;}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 26 Mar 2018 11:27:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-a-value-if-we-have-a-big-messy-data/m-p/448595#M112855</guid>
      <dc:creator>AMFR</dc:creator>
      <dc:date>2018-03-26T11:27:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain a value if we have a big messy data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-a-value-if-we-have-a-big-messy-data/m-p/448598#M112856</link>
      <description>&lt;P&gt;How about adding a cleaning step that aligns the TS timestamps:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
input
  ID
  Action $
  TS_SER
  TS
  Verify
  Notecount
;
informat
  TS_SER
  TS
    datetime14.
;
format
  TS_SER
  TS
    datetime14.
;
datalines;
252670 Sign 13DEC17:11:05 13DEC17:11:14 . .
252670 Perform 13DEC17:11:05 13DEC17:11:14 . .
252670 Verify 13DEC17:11:05 13DEC17:11:14  1 1
252670 Sign 13DEC17:15:27 13DEC17:15:41 . .
252670 Perform 13DEC17:15:27 13DEC17:15:41 . .
252670 Verify 13DEC17:15:27 13DEC17:15:41 1 2
252670 Sign 13DEC17:16:28 13DEC17:16:30 . .
252670 Perform 13DEC17:16:28 13DEC17:16:30 . .
252670 Verify 13DEC17:16:28 13DEC17:16:30 1 3
252670 Sign 13DEC17:16:29 13DEC17:16:30 . .
252670 Modify 13DEC17:16:29 13DEC17:16:30 . .
252670 Perform 14DEC17:07:32 14DEC17:07:34 . .
252670 Verify 14DEC17:07:32 14DEC17:07:34 1 4
252670 Sign 14DEC17:07:32 14DEC17:07:34 . .
252670 Perform 14DEC17:09:15 14DEC17:09:15 . .
252670 Verify 14DEC17:09:15 14DEC17:09:15 1 5
252670 Sign 14DEC17:09:15 14DEC17:09:15 . .
252670 Perform 14DEC17:14:18 14DEC17:16:29 . .
252670 Verify 14DEC17:14:18 14DEC17:16:29 1 6
252670 Sign 14DEC17:14:18 14DEC17:14:18 . .
252670 Sign 14DEC17:14:18 14DEC17:16:29 . .
252670 Sign 14DEC17:16:13 14DEC17:16:17 . .
252670 Perform 14DEC17:16:13 14DEC17:16:17 . .
252670 Verify 14DEC17:16:13 14DEC17:16:17 1 7
252670 Modify 14DEC17:16:29 14DEC17:16:29 . .
252670 Perform 14DEC17:16:29 14DEC17:16:29 . .
252670 Sign 14DEC17:16:29 14DEC17:16:29 . .
252670 Perform 14DEC17:19:12 14DEC17:19:15 . .
252670 Verify 14DEC17:19:12 14DEC17:19:15 1 8
252670 Sign 14DEC17:19:12 14DEC17:19:15 . .
252670 Perform 15DEC17:15:27 15DEC17:15:27 . .
252670 Verify 15DEC17:15:27 15DEC17:15:27 1 9
252670 Sign 15DEC17:15:27 15DEC17:15:27 . .
252670 Sign 16DEC17:10:38 16DEC17:10:38 . .
252670 Perform 16DEC17:10:38 16DEC17:10:38 . .
252670 Verify 16DEC17:10:38 16DEC17:10:38 1 10
318672 Sign 13OCT17:20:32 14OCT17:10:11 . .
318672 Modify 13OCT17:20:36 14OCT17:10:11  . .
318672 Modify 13OCT17:20:37 14OCT17:10:11 . .
318672 Modify 13OCT17:20:40 14OCT17:10:11 . .
318672 Modify 13OCT17:20:44 14OCT17:10:11 . .
318672 Modify 13OCT17:20:46 14OCT17:10:11 . .
318672 Modify 13OCT17:23:03 14OCT17:10:11 . .
318672 Sign 13OCT17:23:03 14OCT17:10:11 . .
318672 Sign 13OCT17:23:04 13OCT17:23:04 . .
318672 Verify 14OCT17:10:11 14OCT17:10:11 1 1
318672 Sign 14OCT17:10:11 14OCT17:10:11 . .
318672 Sign 14OCT17:10:26 14OCT17:10:52 . .
318672 Perform 14OCT17:10:26 14OCT17:14:09 . .
318672 Modify 14OCT17:10:52 14OCT17:14:09 . .
318672 Sign 14OCT17:10:54 14OCT17:10:54 . .
318672 Sign 14OCT17:10:54 14OCT17:14:09 . .
318672 Modify 14OCT17:10:54 14OCT17:14:09 . .
318672 Verify 14OCT17:10:54 14OCT17:14:09 1 2
;
run;

proc sort data=temp;
by id ts;
run;

data have; /* "clean" timestamps */
set temp;
by id ts;
retain current_time;
if first.id then current_time = ts;
if ts - current_time &amp;lt; 120 /* 2 minutes */
then ts = current_time;
else current_time = ts;
drop current_time;
run;

proc sql;
create table want as
select
  ID, Action, TS_SER, TS, Verify,
  max(notecount) as notecount
from have
group by id, ts
order by id, ts_ser
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Mar 2018 11:44:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-a-value-if-we-have-a-big-messy-data/m-p/448598#M112856</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-26T11:44:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to retain a value if we have a big messy data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-retain-a-value-if-we-have-a-big-messy-data/m-p/449607#M113170</link>
      <description>&lt;P&gt;Thank you very much for your suggestion. I am still not getting desired output after cleaning step. I am working on better understanding the data. Sometime I feel like I know what I should I do and after a second I am confuse. I am working on other project for now because it was not urgent. I will update you once I start working on it again.&lt;/P&gt;&lt;P&gt;Thanks again, you are very helpful.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Mar 2018 10:43:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-retain-a-value-if-we-have-a-big-messy-data/m-p/449607#M113170</guid>
      <dc:creator>AMFR</dc:creator>
      <dc:date>2018-03-29T10:43:23Z</dc:date>
    </item>
  </channel>
</rss>

