<?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: Finding a value that reoccurs for the first time after a certain period of time in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Finding-a-value-that-reoccurs-for-the-first-time-after-a-certain/m-p/641856#M191394</link>
    <description>&lt;P&gt;Your data shows an earmark of translation from a (lazy programmer) data source that doesn't actually distinguish between DATES and TIMES. Since every single value you show has a time component of 00:00:00 and you named the variable DATE I would suggest making the value a SAS date value instead of the apparent datetime.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This can be accomplished either when the data is brought into SAS by reading with an appropriate informat or modify after read with data step and something like:&lt;/P&gt;
&lt;P&gt;Data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; date = datepart(date);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; format date date9.;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Apr 2020 09:00:39 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-04-22T09:00:39Z</dc:date>
    <item>
      <title>Finding a value that reoccurs for the first time after a certain period of time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-a-value-that-reoccurs-for-the-first-time-after-a-certain/m-p/641805#M191359</link>
      <description>&lt;P&gt;I have been trying to figure out how to do this accurately...&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I have a list of ID's that undergo a certain code assignment. I have pulled this data from Jul1, 2019 onwards.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;E is always the first step and denotes the start of the assignment. There are steps that come after and each step has a date to it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What i need to do is the following:&lt;/P&gt;&lt;P&gt;Of the IDs that had the code E in July 2019 , how many of those IDs did not appear again until 6 months after (in February) I would then repeat the same exercise for other months. i.e aug 2019 E's not appearing until 6 months after and so on.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data is as follows:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;ID&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;code&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;date&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;1234&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;E&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;02JUL2019:00:00:00&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;1234&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;D7&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;03JUL2019:00:00:00&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;1234&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;1S&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;19JUL2019:00:00:00&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;1234&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;E&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;01SEP2019:00:00:00&lt;/P&gt;&lt;/TD&g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gt;&lt;P&gt;03JUL2019:00:00:00&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;232&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;D7&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;05JUL2019:00:00:00&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;232&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;E&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;02AUG2019:00:00:00&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried enumerating the variables but then i am getting stuck on how to pick accounts that had the E in August, no activity in between and then first activity recorded in March 2019 which would be an E. Appreciate any help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Apr 2020 03:23:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-a-value-that-reoccurs-for-the-first-time-after-a-certain/m-p/641805#M191359</guid>
      <dc:creator>TheNovice</dc:creator>
      <dc:date>2020-04-22T03:23:06Z</dc:date>
    </item>
    <item>
      <title>Re: Finding a value that reoccurs for the first time after a certain period of time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-a-value-that-reoccurs-for-the-first-time-after-a-certain/m-p/641810#M191360</link>
      <description>&lt;P&gt;What would the output be for your example data?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Apr 2020 04:16:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-a-value-that-reoccurs-for-the-first-time-after-a-certain/m-p/641810#M191360</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-04-22T04:16:38Z</dc:date>
    </item>
    <item>
      <title>Re: Finding a value that reoccurs for the first time after a certain period of time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-a-value-that-reoccurs-for-the-first-time-after-a-certain/m-p/641822#M191368</link>
      <description>&lt;P&gt;I imagine you can approach like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input id code :$2. date :date9.;
	format date date9.;
	datalines;
1234 E 02JUL2019
1234 D7 03JUL2019
1234 1S 19JUL2019
1234 E 01FEB2020
1234 D7 02SEP2019
;
run;

proc sort data=have;
	by id code date;
run;

data want;
	set have;
	by id code;
	format l_dt date9.;
	l_dt=lag(date);

	if first.code then
		l_dt=.;
	mths_btwn=intck('month', l_dt, date);

	if mths_btwn &amp;gt;=6;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Apr 2020 06:20:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-a-value-that-reoccurs-for-the-first-time-after-a-certain/m-p/641822#M191368</guid>
      <dc:creator>unison</dc:creator>
      <dc:date>2020-04-22T06:20:45Z</dc:date>
    </item>
    <item>
      <title>Re: Finding a value that reoccurs for the first time after a certain period of time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-a-value-that-reoccurs-for-the-first-time-after-a-certain/m-p/641823#M191369</link>
      <description>&lt;P&gt;With hope I understand you correctly then try next code.&lt;/P&gt;
&lt;P&gt;I saved your test data as an excel sheet with suffix xlsx.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname testxl xlsx '/folders/myfolders/flat/test0422.xlsx';

data have; 
 set testxl.sheet1(rename=(date=dtt));
     date = datepart(input(dtt,datetime18.));
     format date date9.;
run;

proc sort data=have; by id date; run;

proc transpose data=have(where=(code='E')) 
               out=temp1(drop=_name_);
  by id;
  var date;
run;

data want (keep=ID date1 date2 dif);
 set temp1;
     array dt col: ;
     do i= 1 to dim(dt)-1;
        date1 = dt(i);
        if date1 = . then leave;
        do j = i+1 to dim(dt);
           date2 = dt(j);
           dif= intck('month',date1,date2); 
                put id= date1= date2= dif=;       
           if dif &amp;gt; 5 then output;
        end;
    end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Apr 2020 06:28:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-a-value-that-reoccurs-for-the-first-time-after-a-certain/m-p/641823#M191369</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-04-22T06:28:53Z</dc:date>
    </item>
    <item>
      <title>Re: Finding a value that reoccurs for the first time after a certain period of time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-a-value-that-reoccurs-for-the-first-time-after-a-certain/m-p/641856#M191394</link>
      <description>&lt;P&gt;Your data shows an earmark of translation from a (lazy programmer) data source that doesn't actually distinguish between DATES and TIMES. Since every single value you show has a time component of 00:00:00 and you named the variable DATE I would suggest making the value a SAS date value instead of the apparent datetime.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This can be accomplished either when the data is brought into SAS by reading with an appropriate informat or modify after read with data step and something like:&lt;/P&gt;
&lt;P&gt;Data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; date = datepart(date);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; format date date9.;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Apr 2020 09:00:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-a-value-that-reoccurs-for-the-first-time-after-a-certain/m-p/641856#M191394</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-04-22T09:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: Finding a value that reoccurs for the first time after a certain period of time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Finding-a-value-that-reoccurs-for-the-first-time-after-a-certain/m-p/643075#M191878</link>
      <description>&lt;P&gt;Thank you so much! it worked &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 26 Apr 2020 16:53:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Finding-a-value-that-reoccurs-for-the-first-time-after-a-certain/m-p/643075#M191878</guid>
      <dc:creator>TheNovice</dc:creator>
      <dc:date>2020-04-26T16:53:58Z</dc:date>
    </item>
  </channel>
</rss>

