<?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 Time difference between each subset of observations in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Time-difference-between-each-subset-of-observations/m-p/389358#M3296</link>
    <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;x &amp;nbsp; &amp;nbsp;date&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;01/01/2008&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1 &amp;nbsp; &amp;nbsp;01/10/2008&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1 &amp;nbsp; &amp;nbsp;02/15/2008&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1 &amp;nbsp; &amp;nbsp;03/25/2008&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2&amp;nbsp; &amp;nbsp; 01/17/2008&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2&amp;nbsp; &amp;nbsp; 04/28/2008&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2 &amp;nbsp; &amp;nbsp;05/07/2008&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;and I want to (1) obtain the difference between dates (in # days) for each specific value of x, and (2) identify observations whose time difference with the previous one is less than 30 days. In other words, I want this data:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;x &amp;nbsp; &amp;nbsp;date &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;difference &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; identifier&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;01/01/2008 &amp;nbsp; &amp;nbsp; &amp;nbsp;NA &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1 &amp;nbsp; &amp;nbsp;01/10/2008&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;9&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1 &amp;nbsp; &amp;nbsp;02/15/2008&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1 &amp;nbsp; &amp;nbsp;03/25/2008&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;40&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2&amp;nbsp; &amp;nbsp; 01/17/2008 &amp;nbsp; &amp;nbsp; &amp;nbsp;NA &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2&amp;nbsp; &amp;nbsp; 04/28/2008&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;63&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2 &amp;nbsp; &amp;nbsp;05/07/2008&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any idea/help is really appreciated!&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sat, 19 Aug 2017 22:54:17 GMT</pubDate>
    <dc:creator>Alireza_Boloori</dc:creator>
    <dc:date>2017-08-19T22:54:17Z</dc:date>
    <item>
      <title>Time difference between each subset of observations</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Time-difference-between-each-subset-of-observations/m-p/389358#M3296</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;x &amp;nbsp; &amp;nbsp;date&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;01/01/2008&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1 &amp;nbsp; &amp;nbsp;01/10/2008&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1 &amp;nbsp; &amp;nbsp;02/15/2008&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1 &amp;nbsp; &amp;nbsp;03/25/2008&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2&amp;nbsp; &amp;nbsp; 01/17/2008&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2&amp;nbsp; &amp;nbsp; 04/28/2008&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2 &amp;nbsp; &amp;nbsp;05/07/2008&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;and I want to (1) obtain the difference between dates (in # days) for each specific value of x, and (2) identify observations whose time difference with the previous one is less than 30 days. In other words, I want this data:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;x &amp;nbsp; &amp;nbsp;date &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;difference &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; identifier&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp;01/01/2008 &amp;nbsp; &amp;nbsp; &amp;nbsp;NA &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1 &amp;nbsp; &amp;nbsp;01/10/2008&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;9&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1 &amp;nbsp; &amp;nbsp;02/15/2008&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1 &amp;nbsp; &amp;nbsp;03/25/2008&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;40&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2&amp;nbsp; &amp;nbsp; 01/17/2008 &amp;nbsp; &amp;nbsp; &amp;nbsp;NA &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2&amp;nbsp; &amp;nbsp; 04/28/2008&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;63&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2 &amp;nbsp; &amp;nbsp;05/07/2008&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any idea/help is really appreciated!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Aug 2017 22:54:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Time-difference-between-each-subset-of-observations/m-p/389358#M3296</guid>
      <dc:creator>Alireza_Boloori</dc:creator>
      <dc:date>2017-08-19T22:54:17Z</dc:date>
    </item>
    <item>
      <title>Re: Time difference between each subset of observations</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Time-difference-between-each-subset-of-observations/m-p/389363#M3298</link>
      <description>&lt;P&gt;This is easy enough except that unless I'm misunderstanding what you want some of the differences in your output aren't correct.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is my code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile datalines dlm=",";
	input x date mmddyy10.;
	format date mmddyy10.;
	datalines;
1,01/01/2008
1,01/10/2008
1,02/15/2008
1,03/25/2008
2,01/17/2008
2,04/28/2008
2,05/07/2008
;
run;


proc sort data=have;
	by x;
run;

data want(drop=ldate);
	set have;
	by x;
	ldate=lag(date);
	if first.x then do;
		difference=.;
		identifier=0;
	end;
	else do;
		difference=date-ldate;
		if difference&amp;lt;30 then identifier=1;
		else identifier=0;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also SAS uses&amp;nbsp;the missing symbol . instead of NA so my output looks like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Differences.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/14560iA96C2B754082F9F4/image-size/large?v=v2&amp;amp;px=999" role="button" title="Differences.png" alt="Differences.png" /&gt;&lt;/span&gt;&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>Sat, 19 Aug 2017 23:59:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Time-difference-between-each-subset-of-observations/m-p/389363#M3298</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2017-08-19T23:59:23Z</dc:date>
    </item>
    <item>
      <title>Re: Time difference between each subset of observations</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Time-difference-between-each-subset-of-observations/m-p/389365#M3299</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
       input x date mmddtt10.;
       format date mmddyy10.;
cards;
1    01/01/2008
1    01/10/2008
1    02/15/2008
1    03/25/2008
2    01/17/2008
2    04/28/2008
2    05/07/2008
; run;

data want;
 set have;
  by x;
       prev_dt = lag(date);
       if first.x then prev_dt = .;
       difference = date - prev_dt;
       if difference &amp;lt; 30 then identifier = 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 20 Aug 2017 00:07:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Time-difference-between-each-subset-of-observations/m-p/389365#M3299</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-08-20T00:07:56Z</dc:date>
    </item>
  </channel>
</rss>

