<?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: Follow-up in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Follow-up/m-p/646258#M193286</link>
    <description>&lt;P&gt;for Base SAS, a Do Whitlock loop can be written to iterate through this, giving respect to a by statement.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;So many resources -- first link from Google:&lt;BR /&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings12/052-2012.pdf" target="_blank" rel="noopener"&gt;https://support.sas.com/resources/papers/proceedings12/052-2012.pdf&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 08 May 2020 16:29:52 GMT</pubDate>
    <dc:creator>PhilC</dc:creator>
    <dc:date>2020-05-08T16:29:52Z</dc:date>
    <item>
      <title>Follow-up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Follow-up/m-p/646254#M193283</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a question. I need to followup an object until 3 year period with a condition that the object has not been sold i last 5 year.&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;Object&amp;nbsp; &amp;nbsp; date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; value&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01-01-2003&amp;nbsp; &amp;nbsp; --&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01-01-2004&amp;nbsp; &amp;nbsp; --&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01-02-2009&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01-01-2010&amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01-01-2016&amp;nbsp; &amp;nbsp; &amp;nbsp;--&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01-01-2017&amp;nbsp; &amp;nbsp; --&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;what i need is first to check if there is a difference between the two dates within the same object is more than 5 years, if it is true then followup the same object upto 3 year. ie the difference between the third and second is more than five years, so it will be our index date and it shall be followed upto 3 years.&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2020 15:51:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Follow-up/m-p/646254#M193283</guid>
      <dc:creator>ifti_ch2002</dc:creator>
      <dc:date>2020-05-08T15:51:34Z</dc:date>
    </item>
    <item>
      <title>Re: Follow-up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Follow-up/m-p/646258#M193286</link>
      <description>&lt;P&gt;for Base SAS, a Do Whitlock loop can be written to iterate through this, giving respect to a by statement.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;So many resources -- first link from Google:&lt;BR /&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings12/052-2012.pdf" target="_blank" rel="noopener"&gt;https://support.sas.com/resources/papers/proceedings12/052-2012.pdf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 May 2020 16:29:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Follow-up/m-p/646258#M193286</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2020-05-08T16:29:52Z</dc:date>
    </item>
    <item>
      <title>Re: Follow-up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Follow-up/m-p/646280#M193293</link>
      <description>Please post what you expect as result.</description>
      <pubDate>Fri, 08 May 2020 17:43:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Follow-up/m-p/646280#M193293</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-05-08T17:43:11Z</dc:date>
    </item>
    <item>
      <title>Re: Follow-up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Follow-up/m-p/646283#M193296</link>
      <description>The result is in the value column.</description>
      <pubDate>Fri, 08 May 2020 18:14:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Follow-up/m-p/646283#M193296</guid>
      <dc:creator>ifti_ch2002</dc:creator>
      <dc:date>2020-05-08T18:14:00Z</dc:date>
    </item>
    <item>
      <title>Re: Follow-up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Follow-up/m-p/646301#M193302</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/267482"&gt;@ifti_ch2002&lt;/a&gt; &lt;BR /&gt;&lt;BR /&gt;Perhaps you can show more input.</description>
      <pubDate>Fri, 08 May 2020 19:03:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Follow-up/m-p/646301#M193302</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2020-05-08T19:03:52Z</dc:date>
    </item>
    <item>
      <title>Re: Follow-up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Follow-up/m-p/646333#M193321</link>
      <description>&lt;PRE&gt;data test;
infile datalines missover; 
   input IDnumber @3 date  mmddyy10. @12 f;
   datalines;  
1 4-7-2003 
1 4-7-2009 1
1 4-7-2010 2
1 4-7-2011 3
1 4-7-2012 4
1 4-7-2013 
1 4-7-2014 
1 4-7-2015 
1 4-7-2016 
1 4-7-2018 
2 4-7-2005 
2 4-7-2011 1
2 4-7-2012 2
2 4-7-2013 3
2 4-7-2014 4
2 4-7-2015 
2 4-7-2016 
2 4-7-2017 
2 4-7-2018 
2 4-7-2019 
2 4-7-2020 
;       
run; 

data test1;
set test;
format date lag_date mmddyy10.;
run;&lt;/PRE&gt;&lt;P&gt;1) f=1 if the difference between the current date and lag_date (previous) is greater than 5 years&lt;/P&gt;&lt;P&gt;2) f=1 will be the index date&lt;/P&gt;&lt;P&gt;3)f+1 if the difference between the following date and index date is less than 3 years&lt;/P&gt;</description>
      <pubDate>Sat, 09 May 2020 01:24:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Follow-up/m-p/646333#M193321</guid>
      <dc:creator>ifti_ch2002</dc:creator>
      <dc:date>2020-05-09T01:24:58Z</dc:date>
    </item>
    <item>
      <title>Re: Follow-up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Follow-up/m-p/646366#M193331</link>
      <description>Thanks, I understand what you are describing much better. Are you familiar with INTCK and INTNX? Great functions. I see you using INTNX to count year "intervals".&lt;BR /&gt;&lt;BR /&gt;If f=1 then date_3yrs_after_index = INTNX("year",date,3,"Same");</description>
      <pubDate>Sat, 09 May 2020 23:58:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Follow-up/m-p/646366#M193331</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2020-05-09T23:58:19Z</dc:date>
    </item>
    <item>
      <title>Re: Follow-up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Follow-up/m-p/646424#M193361</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15329"&gt;@PhilC&lt;/a&gt;: I think that the variable "f" is the requested result and not present in the data. &lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/267482"&gt;@ifti_ch2002&lt;/a&gt; : Please specify clearly what you have and want you want, it is quite uncommon to present one dataset containing both at the same time. And you wrote "3)f+1 if the difference between the &lt;EM&gt;following date&lt;/EM&gt; and index date is less than 3 years" - with "following date" the date of the observation is meant in which f is set to f+1? And "less than" seems to be wrong, because the difference between index-Date and current date in the fifth observation is three and not less than three.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some ideas:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;retain f, lastDate and indexDate&lt;/LI&gt;
&lt;LI&gt;use by IdNumber and reset f and lastDate if first.IdNumber&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 May 2020 21:03:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Follow-up/m-p/646424#M193361</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-05-09T21:03:00Z</dc:date>
    </item>
    <item>
      <title>Re: Follow-up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Follow-up/m-p/646426#M193362</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;sorry for that. I should be more specifically define what i have and what i need.&lt;/P&gt;&lt;P&gt;f column is what i required.&lt;/P&gt;&lt;P&gt;Following date i mean where the value of f+1 will be.&lt;/P&gt;&lt;P&gt;And i mean less than or euql to 3 years&lt;/P&gt;</description>
      <pubDate>Sat, 09 May 2020 22:32:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Follow-up/m-p/646426#M193362</guid>
      <dc:creator>ifti_ch2002</dc:creator>
      <dc:date>2020-05-09T22:32:00Z</dc:date>
    </item>
    <item>
      <title>Re: Follow-up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Follow-up/m-p/646429#M193365</link>
      <description>&amp;amp;gt;&amp;amp;gt;@PhilC: I think that the variable "f" is the requested result and not present in the data&lt;BR /&gt;&lt;BR /&gt;Indeed, but once f is set to one. &lt;BR /&gt;&lt;BR /&gt;@ifti ? What do think about the Do Whitlock loop? Was that helpful? If so, how have you tried using it?&lt;BR /&gt;&lt;BR /&gt;Do you program primarily using data steps or by SQL? Andreas' point of having a "have" and "want" data set helps us when you show us what you have coded. Give us your latest try at it.</description>
      <pubDate>Sun, 10 May 2020 00:11:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Follow-up/m-p/646429#M193365</guid>
      <dc:creator>PhilC</dc:creator>
      <dc:date>2020-05-10T00:11:51Z</dc:date>
    </item>
    <item>
      <title>Re: Follow-up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Follow-up/m-p/646432#M193368</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/267482"&gt;@ifti_ch2002&lt;/a&gt;&amp;nbsp;wrote:
&lt;P class="1589070762621"&gt;...&lt;/P&gt;
&lt;P class="1589070755415"&gt;1&lt;SPAN style="font-size: 14px;"&gt;) f=1 if the difference between the current date and lag_date (previous) is greater than 5 years&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;2) f=1 will be the index date&lt;/P&gt;
&lt;P&gt;3)f+1 if the difference between the following date and index date is less than 3 years&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;To check the first thing you need to get the change in DATE between observations.&amp;nbsp; LAG() will help.&lt;/P&gt;
&lt;P&gt;For the second one I am going jump to the conclusion that you meant to say that when there is a jump of over 5 years you want to&lt;STRONG&gt; set F to 1&lt;/STRONG&gt; AND also &lt;STRONG&gt;remember what DATE was at that time&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;For the third one I am going to jump to another conclusion that you want to keep incrementing F as long as the difference from the saved index date is &amp;lt;= 3 years.&amp;nbsp; &lt;STRONG&gt;AND that when it is not then you set F to missing&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So let's setup your sample data with your expected values as WANT (instead of F).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  input IDnumber date  :mmddyy10. want;
  format date yymmdd10.;
datalines;
1 4-7-2003 .
1 4-7-2009 1
1 4-7-2010 2
1 4-7-2011 3
1 4-7-2012 4
1 4-7-2013 .
1 4-7-2014 .
1 4-7-2015 .
1 4-7-2016 .
1 4-7-2018 .
2 4-7-2005 .
2 4-7-2011 1
2 4-7-2012 2
2 4-7-2013 3
2 4-7-2014 4
2 4-7-2015 .
2 4-7-2016 .
2 4-7-2017 .
2 4-7-2018 .
2 4-7-2019 .
2 4-7-2020 .
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So it is pretty straight forward to code once the rules are clear. Remember to call the LAG() function on every observation so it sees every value.&amp;nbsp; But don't use the resuliting difference when you are starting a new group.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
  set have;
  by idnumber date ;
  yrdif = intck('year',lag(date),date,'cont');
  if first.idnumber then call missing(yrdif,index_date,f);
  if f then do;
    if intck('year',index_date,date,'cont') &amp;lt;= 3 then f+1;
    else f=.;
  end;
  else if yrdif &amp;gt;= 5 then do;
    index_date=date;
    f=1;
  end;
  format index_date yymmdd10.;
  retain index_date f;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;Obs    IDnumber          date    want    yrdif    index_date    f

  1        1       2003-04-07      .       .               .    .
  2        1       2009-04-07      1       6      2009-04-07    1
  3        1       2010-04-07      2       1      2009-04-07    2
  4        1       2011-04-07      3       1      2009-04-07    3
  5        1       2012-04-07      4       1      2009-04-07    4
  6        1       2013-04-07      .       1      2009-04-07    .
  7        1       2014-04-07      .       1      2009-04-07    .
  8        1       2015-04-07      .       1      2009-04-07    .
  9        1       2016-04-07      .       1      2009-04-07    .
 10        1       2018-04-07      .       2      2009-04-07    .
 11        2       2005-04-07      .       .               .    .
 12        2       2011-04-07      1       6      2011-04-07    1
 13        2       2012-04-07      2       1      2011-04-07    2
 14        2       2013-04-07      3       1      2011-04-07    3
 15        2       2014-04-07      4       1      2011-04-07    4
 16        2       2015-04-07      .       1      2011-04-07    .
 17        2       2016-04-07      .       1      2011-04-07    .
 18        2       2017-04-07      .       1      2011-04-07    .
 19        2       2018-04-07      .       1      2011-04-07    .
 20        2       2019-04-07      .       1      2011-04-07    .
 21        2       2020-04-07      .       1      2011-04-07    .&lt;/PRE&gt;</description>
      <pubDate>Sun, 10 May 2020 00:39:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Follow-up/m-p/646432#M193368</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-05-10T00:39:49Z</dc:date>
    </item>
    <item>
      <title>Re: Follow-up</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Follow-up/m-p/646518#M193432</link>
      <description>Thanks a lot, i really appriciate.</description>
      <pubDate>Sun, 10 May 2020 15:17:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Follow-up/m-p/646518#M193432</guid>
      <dc:creator>ifti_ch2002</dc:creator>
      <dc:date>2020-05-10T15:17:57Z</dc:date>
    </item>
  </channel>
</rss>

