<?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: similar observations sequence and repeat time.How to gain? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/similar-observations-sequence-and-repeat-time-How-to-gain/m-p/31998#M6156</link>
    <description>Ksharp:&lt;BR /&gt;
I tried. Yes, it works.&lt;BR /&gt;
&lt;BR /&gt;
Thank you very much. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
    <pubDate>Mon, 07 Jun 2010 09:09:51 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2010-06-07T09:09:51Z</dc:date>
    <item>
      <title>similar observations sequence and repeat time.How to gain?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/similar-observations-sequence-and-repeat-time-How-to-gain/m-p/31992#M6150</link>
      <description>I got a big data set, which has the form of &lt;BR /&gt;
say in work.a;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://s288.photobucket.com/albums/ll186/sixtyinch/for%20SASDATA/?action=view&amp;amp;current=TE1.jpg" target="_blank"&gt;&lt;IMG src="http://i288.photobucket.com/albums/ll186/sixtyinch/for%20SASDATA/TE1.jpg" border="0" alt="SMALLforSAS" /&gt;&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
where Add and T are the variable name. and "A".... are the observations;&lt;BR /&gt;
&lt;BR /&gt;
who can told me how to write a code to generate the belowing table?&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
 &lt;BR /&gt;
&lt;A href="http://s288.photobucket.com/albums/ll186/sixtyinch/for%20SASDATA/?action=view&amp;amp;current=TE.jpg" target="_blank"&gt;&lt;IMG src="http://i288.photobucket.com/albums/ll186/sixtyinch/for%20SASDATA/TE.jpg" border="0" alt="2" /&gt;&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Thank you very much...AND hope someone can help me, as i am quite not good at SAS...</description>
      <pubDate>Fri, 04 Jun 2010 15:23:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/similar-observations-sequence-and-repeat-time-How-to-gain/m-p/31992#M6150</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-06-04T15:23:36Z</dc:date>
    </item>
    <item>
      <title>Re: similar observations sequence and repeat time.How to gain?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/similar-observations-sequence-and-repeat-time-How-to-gain/m-p/31993#M6151</link>
      <description>you can sort the dataset and use retain function to calculate new columns.</description>
      <pubDate>Fri, 04 Jun 2010 15:37:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/similar-observations-sequence-and-repeat-time-How-to-gain/m-p/31993#M6151</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-06-04T15:37:58Z</dc:date>
    </item>
    <item>
      <title>Re: similar observations sequence and repeat time.How to gain?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/similar-observations-sequence-and-repeat-time-How-to-gain/m-p/31994#M6152</link>
      <description>Hi. The code is a little long. But I got it.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data area;&lt;BR /&gt;
  input area : $1. time : mmddyy10. ;&lt;BR /&gt;
  format time mmddyy10.;&lt;BR /&gt;
datalines;&lt;BR /&gt;
A 2/1/2007&lt;BR /&gt;
A 10/11/2008&lt;BR /&gt;
A 4/21/2009&lt;BR /&gt;
B 7/2/2008&lt;BR /&gt;
C 1/21/2008&lt;BR /&gt;
C 9/12/2009&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
*to get repeated sequence duration1 duration2;&lt;BR /&gt;
data temp;&lt;BR /&gt;
  set area;&lt;BR /&gt;
  by area;&lt;BR /&gt;
  retain base repeated 0;&lt;BR /&gt;
  if first.area then do;&lt;BR /&gt;
                       repeated=not(repeated);&lt;BR /&gt;
					   sequence=0;&lt;BR /&gt;
					   base=time;&lt;BR /&gt;
					 end;&lt;BR /&gt;
	duration1=dif(time);&lt;BR /&gt;
	sequence+1;&lt;BR /&gt;
	duration2=time-base;&lt;BR /&gt;
	drop base;&lt;BR /&gt;
run;&lt;BR /&gt;
*to adjust duration1;&lt;BR /&gt;
data tmp;&lt;BR /&gt;
  set temp;&lt;BR /&gt;
  by area;&lt;BR /&gt;
  if first.area then duration1=0;&lt;BR /&gt;
run;&lt;BR /&gt;
*to get duration3 is somewhat complex;&lt;BR /&gt;
data index;&lt;BR /&gt;
  set tmp;&lt;BR /&gt;
  by area;&lt;BR /&gt;
  if first.area then delete;&lt;BR /&gt;
  keep area time;&lt;BR /&gt;
run;&lt;BR /&gt;
data merged;&lt;BR /&gt;
  merge tmp index(rename=(time=t));&lt;BR /&gt;
  by area;&lt;BR /&gt;
run;&lt;BR /&gt;
proc format;&lt;BR /&gt;
  value fmt&lt;BR /&gt;
        0,. = 'Truncated';&lt;BR /&gt;
run;&lt;BR /&gt;
data result;&lt;BR /&gt;
  set merged;&lt;BR /&gt;
  duration3= t - time;&lt;BR /&gt;
  format duration3 fmt.;&lt;BR /&gt;
  drop t;&lt;BR /&gt;
run;&lt;BR /&gt;
proc print noobs;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Sun, 06 Jun 2010 03:41:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/similar-observations-sequence-and-repeat-time-How-to-gain/m-p/31994#M6152</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-06-06T03:41:33Z</dc:date>
    </item>
    <item>
      <title>Re: similar observations sequence and repeat time.How to gain?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/similar-observations-sequence-and-repeat-time-How-to-gain/m-p/31995#M6153</link>
      <description>Hi. The code is a little long. But I got it.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data area;&lt;BR /&gt;
  input area : $1. time : mmddyy10. ;&lt;BR /&gt;
  format time mmddyy10.;&lt;BR /&gt;
datalines;&lt;BR /&gt;
A 2/1/2007&lt;BR /&gt;
A 10/11/2008&lt;BR /&gt;
A 4/21/2009&lt;BR /&gt;
B 7/2/2008&lt;BR /&gt;
C 1/21/2008&lt;BR /&gt;
C 9/12/2009&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
*to get repeated sequence duration1 duration2;&lt;BR /&gt;
data temp;&lt;BR /&gt;
  set area;&lt;BR /&gt;
  by area;&lt;BR /&gt;
  retain base repeated 0;&lt;BR /&gt;
  if first.area then do;&lt;BR /&gt;
                       repeated=not(repeated);&lt;BR /&gt;
					   sequence=0;&lt;BR /&gt;
					   base=time;&lt;BR /&gt;
					 end;&lt;BR /&gt;
	duration1=dif(time);&lt;BR /&gt;
	sequence+1;&lt;BR /&gt;
	duration2=time-base;&lt;BR /&gt;
	drop base;&lt;BR /&gt;
run;&lt;BR /&gt;
*to adjust duration1;&lt;BR /&gt;
data tmp;&lt;BR /&gt;
  set temp;&lt;BR /&gt;
  by area;&lt;BR /&gt;
  if first.area then duration1=0;&lt;BR /&gt;
run;&lt;BR /&gt;
*to get duration3 is somewhat complex;&lt;BR /&gt;
data index;&lt;BR /&gt;
  set tmp;&lt;BR /&gt;
  by area;&lt;BR /&gt;
  if first.area then delete;&lt;BR /&gt;
  keep area time;&lt;BR /&gt;
run;&lt;BR /&gt;
data merged;&lt;BR /&gt;
  merge tmp index(rename=(time=t));&lt;BR /&gt;
  by area;&lt;BR /&gt;
run;&lt;BR /&gt;
proc format;&lt;BR /&gt;
  value fmt&lt;BR /&gt;
        0,. = 'Truncated';&lt;BR /&gt;
run;&lt;BR /&gt;
data result;&lt;BR /&gt;
  set merged;&lt;BR /&gt;
  duration3= t - time;&lt;BR /&gt;
  format duration3 fmt.;&lt;BR /&gt;
  drop t;&lt;BR /&gt;
run;&lt;BR /&gt;
proc print noobs;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Sun, 06 Jun 2010 03:43:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/similar-observations-sequence-and-repeat-time-How-to-gain/m-p/31995#M6153</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-06-06T03:43:55Z</dc:date>
    </item>
    <item>
      <title>Re: similar observations sequence and repeat time.How to gain?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/similar-observations-sequence-and-repeat-time-How-to-gain/m-p/31996#M6154</link>
      <description>Sort by Address and Time, then do something like this (untested code).&lt;BR /&gt;
&lt;BR /&gt;
data inter / view=inter;&lt;BR /&gt;
set..&lt;BR /&gt;
by address;&lt;BR /&gt;
retain startTime;&lt;BR /&gt;
rowcount=_n_;&lt;BR /&gt;
lagTime=lag(time).&lt;BR /&gt;
repeated=1;&lt;BR /&gt;
&lt;BR /&gt;
if first.address then&lt;BR /&gt;
do;&lt;BR /&gt;
  sequence=0;&lt;BR /&gt;
  lagTime=time;&lt;BR /&gt;
  startTime=time;&lt;BR /&gt;
  if last.address then repeated=0;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
sequence+1;&lt;BR /&gt;
duration1=lagTime-time;&lt;BR /&gt;
duration2=time-startTime;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table want as&lt;BR /&gt;
select l.*,r.duration1 as duration3&lt;BR /&gt;
from inter as l left join inter as r&lt;BR /&gt;
on l.rowcount=(r.rowcount+1) and l.address=r.address;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick

Message was edited by: Patrick</description>
      <pubDate>Sun, 06 Jun 2010 03:52:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/similar-observations-sequence-and-repeat-time-How-to-gain/m-p/31996#M6154</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-06-06T03:52:32Z</dc:date>
    </item>
    <item>
      <title>Re: similar observations sequence and repeat time.How to gain?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/similar-observations-sequence-and-repeat-time-How-to-gain/m-p/31997#M6155</link>
      <description>thank u very much!!&lt;BR /&gt;
&lt;BR /&gt;
i will try to check it.</description>
      <pubDate>Sun, 06 Jun 2010 14:18:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/similar-observations-sequence-and-repeat-time-How-to-gain/m-p/31997#M6155</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-06-06T14:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: similar observations sequence and repeat time.How to gain?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/similar-observations-sequence-and-repeat-time-How-to-gain/m-p/31998#M6156</link>
      <description>Ksharp:&lt;BR /&gt;
I tried. Yes, it works.&lt;BR /&gt;
&lt;BR /&gt;
Thank you very much. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Mon, 07 Jun 2010 09:09:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/similar-observations-sequence-and-repeat-time-How-to-gain/m-p/31998#M6156</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-06-07T09:09:51Z</dc:date>
    </item>
    <item>
      <title>Re: similar observations sequence and repeat time.How to gain?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/similar-observations-sequence-and-repeat-time-How-to-gain/m-p/31999#M6157</link>
      <description>the final work, i use is based on ksharp's answer, however, with some function usage , like lags, suggested by Patrick. and get the work done.&lt;BR /&gt;
&lt;BR /&gt;
Come to say thank you both two again.:)</description>
      <pubDate>Tue, 08 Jun 2010 16:00:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/similar-observations-sequence-and-repeat-time-How-to-gain/m-p/31999#M6157</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-06-08T16:00:22Z</dc:date>
    </item>
  </channel>
</rss>

