<?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: Counting the number of observations between rows (same ID) and output the ID that meet the crite in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429394#M13254</link>
    <description>&lt;P&gt;Good morning from Chicago, Welcome to the SAS forum and thank you for the steadfast communication in clarifying. I'll be right back hopefully with the code or perhaps for some more clarifications.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 20 Jan 2018 16:59:37 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-01-20T16:59:37Z</dc:date>
    <item>
      <title>Counting the number of observations between rows (same ID) and output the ID that meet the criteria?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429338#M13242</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot in advance! Any suggestion would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with multiple observations per Client ID and have to select just the clients that meet the following criteria:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;The client must have an &lt;U&gt;initial interview&lt;/U&gt;.&lt;/LI&gt;&lt;LI&gt;The client must have at least one &lt;U&gt;service &lt;/U&gt;(cleaning house, delivering groceries, etc.) delivered within &lt;U&gt;6 months&lt;/U&gt; of the &lt;U&gt;initial interview&lt;/U&gt;.&lt;/LI&gt;&lt;LI&gt;The client must have at least &lt;U&gt;3 re-interviews&lt;/U&gt; &lt;U&gt;5-7 months&lt;/U&gt; apart from each other.&lt;/LI&gt;&lt;LI&gt;The client must have at least one &lt;U&gt;service&lt;/U&gt; delivered between the &lt;U&gt;re-interviews&lt;/U&gt;.&lt;/LI&gt;&lt;LI&gt;Get a final dataset with the qualifying Client ID and only the qualifying observations.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Client ID&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Category&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;001&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;initial interview&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;02/01/2016&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;001&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;service delivered&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;07/01/2016&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;001&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;re-interview&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;08/01/2016&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;001&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;service delivered&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;10/01/2016&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;001&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;re-interview&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;01/01/2017&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;001&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;service delivered&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;03/01/2017&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;001&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;re-interview&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;08/01/2017&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;002&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;initial interview&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;02/01/2016&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;002&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;service delivered&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;03/01/2016&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;002&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;re-interview&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;08/01/2016&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;002&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;service delivered&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;10/01/2016&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;002&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;re-interview&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;01/01/2017&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;002&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;service delivered&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;03/01/2017&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;002&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;re-interview&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;08/01/2017&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;003&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;initial interview&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;02/01/2016&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;003&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;re-interview&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;08/01/2016&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;003&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;service delivered&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;10/01/2016&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;003&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;re-interview&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;01/01/2017&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;003&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;service delivered&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;03/01/2017&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;003&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;re-interview&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;08/01/2017&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;004&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;initial interview&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;02/01/2016&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;004&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;service delivered&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;03/01/2016&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;004&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;re-interview&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;08/01/2016&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;004&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;service delivered&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;10/01/2016&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;004&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;re-interview&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;01/01/2017&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;004&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;service delivered&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;03/01/2017&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;004&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;re-interview&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;08/01/2017&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;004&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;service delivered&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;09/01/2017&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;004&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;re-interview&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;12/01/2017&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;The only client meeting the criteria is client 002 and part of client 004. Because:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Client 001 had a service after the initial interview that was delivered after 6 months of the initial interview.&lt;/LI&gt;&lt;LI&gt;Client 003 had an initial interview and then a re-interview with no service(s) in between&lt;/LI&gt;&lt;LI&gt;Client 004 had a re-interview (12/01/2017) that was only 4 months from the previous re-interview.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output should be:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Client ID&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Category&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;002&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;initial interview&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;02/01/2016&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;002&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;service delivered&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;03/01/2016&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;002&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;re-interview&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;08/01/2016&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;002&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;service delivered&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;10/01/2016&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;002&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;re-interview&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;01/01/2017&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;002&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;service delivered&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;03/01/2017&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;002&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;re-interview&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;08/01/2017&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;004&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;initial interview&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;02/01/2016&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;004&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;service delivered&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;03/01/2016&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;004&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;re-interview&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;08/01/2016&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;004&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;service delivered&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;10/01/2016&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;004&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;re-interview&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;01/01/2017&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;004&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;service delivered&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;03/01/2017&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;004&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;re-interview&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;08/01/2017&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;004&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;service delivered&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;09/01/2017&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jan 2018 01:35:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429338#M13242</guid>
      <dc:creator>Asileon</dc:creator>
      <dc:date>2018-01-20T01:35:58Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observations between rows (same ID) and output the ID that meet the crite</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429341#M13243</link>
      <description>&lt;P&gt;How about putting in a little more effort and generating SAS code for data set generation.&amp;nbsp; And possibly, in addition to text describing record types, you might also include code numbers or letters.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jan 2018 03:39:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429341#M13243</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-01-20T03:39:58Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observations between rows (same ID) and output the ID that meet the crite</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429342#M13244</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;your data and questions are confusing to me&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;you said&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only client meeting the criteria is client 002 and part of client 004. Because:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Client 001 had a service after the initial interview that was delivered after 6 months of the initial interview.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;but 002 also has same issue&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;002&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;initial interview&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;02/01/2016&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;002&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;service delivered&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;03/01/2016&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;002&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;re-interview&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;08/01/2016&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;002&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;service delivered&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;10/01/2016&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Sat, 20 Jan 2018 04:29:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429342#M13244</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-01-20T04:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observations between rows (same ID) and output the ID that meet the crite</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429344#M13245</link>
      <description>&lt;P&gt;In your example, all dates are on the first day of the month. Do the dates represent months?&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jan 2018 05:12:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429344#M13245</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-01-20T05:12:53Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observations between rows (same ID) and output the ID that meet the crite</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429345#M13246</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37783"&gt;@kiranv_&lt;/a&gt;&amp;nbsp; &amp;nbsp; OP's question is fairly clear as far as client 002 is concerned.I had a look at this question when i was about to leave my college lab and it's pretty straight forward except the part qualification(eg client 004). However since my own non sas assignments&amp;nbsp;in school that's due in for next week is in a mess, I am afraid I didn't bother though excited.&lt;/P&gt;&lt;P&gt;Anyway, to clarify client 002&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Client 002 had the first aka &lt;STRONG&gt;initial interview on 02/01/2016&amp;nbsp;&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;&lt;EM&gt;The client must have at least one&amp;nbsp;&lt;U&gt;service&amp;nbsp;&lt;/U&gt;(cleaning house, delivering groceries, etc.) delivered within&amp;nbsp;&lt;U&gt;6 months&lt;/U&gt;&amp;nbsp;of the&amp;nbsp;&lt;U&gt;initial interview-- Client 002 had the first serivice post the initial interview on 03/01/2016 which is the subsequent month and that falls within th condition stated above&lt;/U&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;&lt;EM&gt;The client must have at least&amp;nbsp;&lt;U&gt;3 re-interviews&lt;/U&gt;&amp;nbsp;&lt;U&gt;5-7 months&lt;/U&gt;&amp;nbsp;apart from each other---intck aka intevals between the 3 re interviews for client002 do fall in the range &amp;gt;=5 and &amp;lt;=7&lt;/EM&gt;&lt;/STRONG&gt;&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;&lt;EM&gt;The client must have at least one&amp;nbsp;&lt;U&gt;service&lt;/U&gt;&amp;nbsp;delivered between the&amp;nbsp;&lt;U&gt;re-interviews&lt;/U&gt;.- self explanatory just by looking at data&lt;/EM&gt;&lt;/STRONG&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/187861"&gt;@Asileon&lt;/a&gt;&amp;nbsp;What i wanna you to clarify is-&amp;nbsp; "Part of an id that qualifies as in the case of 004"&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;1. If i were to pick only those id's that qualify on the basis of satisfying all the conditions, the "part of client004" concerns me, that is it means like pick the obs in all ids that qualify and leave the rest?????? or is it pick only those id's that satisfy "all" conditions&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;2.Are you using SAS 9.4, this is important to me for me to attempt using more short cuts&amp;nbsp;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;3. I am doing you a favor by creating data have as follows:&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ClientID Category &amp;amp; $20. Date : mmddyy10.;
format date mmddyy10.;
datalines;
1	initial interview	2/1/2016
1	service delivered	7/1/2016
1	re-interview	8/1/2016
1	service delivered	10/1/2016
1	re-interview	1/1/2017
1	service delivered	3/1/2017
1	re-interview	8/1/2017
2	initial interview	2/1/2016
2	service delivered	3/1/2016
2	re-interview	8/1/2016
2	service delivered	10/1/2016
2	re-interview	1/1/2017
2	service delivered	3/1/2017
2	re-interview	8/1/2017
3	initial interview	2/1/2016
3	re-interview	8/1/2016
3	service delivered	10/1/2016
3	re-interview	1/1/2017
3	service delivered	3/1/2017
3	re-interview	8/1/2017
4	initial interview	2/1/2016
4	service delivered	3/1/2016
4	re-interview	8/1/2016
4	service delivered	10/1/2016
4	re-interview	1/1/2017
4	service delivered	3/1/2017
4	re-interview	8/1/2017
4	service delivered	9/1/2017
4	re-interview	12/1/2017
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;PS the bold is just make it look distinct and neat and not to shout &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jan 2018 05:25:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429345#M13246</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-20T05:25:06Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observations between rows (same ID) and output the ID that meet the crite</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429371#M13247</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your feedback. I have been able to create a flag for the re-interviews that are 5-7 months from the previous. The main issue that I am having is using SAS to output just the client IDs that have a re-interview following by another with at least one&amp;nbsp;services in between.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jan 2018 13:08:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429371#M13247</guid>
      <dc:creator>Asileon</dc:creator>
      <dc:date>2018-01-20T13:08:14Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observations between rows (same ID) and output the ID that meet the crite</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429372#M13248</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37783"&gt;@kiranv_&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Client 002 qualify because this client had a service delivered on&lt;STRONG&gt; 03/01/2016&lt;/STRONG&gt; which is within 6 months of the initial interview (one of the criteria). The client will continue to have services even after 6 months of the initial interview, and that is why you see another service 6 months past the initial interview.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;002&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;initial interview&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;02/01/2016&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;002&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;service delivered&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;03/01/2016&lt;/STRONG&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;002&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;re-interview&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;08/01/2016&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;002&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;service delivered&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;STRONG&gt;10/01/2016&lt;/STRONG&gt;&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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jan 2018 13:13:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429372#M13248</guid>
      <dc:creator>Asileon</dc:creator>
      <dc:date>2018-01-20T13:13:18Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observations between rows (same ID) and output the ID that meet the crite</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429373#M13249</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the feedback!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Answering your questions:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/187861" target="_blank"&gt;@Asileon&lt;/A&gt;&amp;nbsp;What i wanna you to clarify is-&amp;nbsp; "Part of an id that qualifies as in the case of 004"&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;1. If i were to pick only those id's that qualify on the basis of satisfying all the conditions, the "part of client004" concerns me, that is it means like pick the obs in all ids that qualify and leave the rest?????? or is it pick only those id's that satisfy "all" conditions&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Answer:&lt;/STRONG&gt;&lt;/U&gt;&lt;STRONG&gt;&amp;nbsp;I want to pick only those id's that satisfy "all" conditions, be able to create a dataset with only those id's, and have the qualifying observations in that dataset. In the example I posted, the dataset will have:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;- client 002, the initial&amp;nbsp;&lt;/STRONG&gt;&lt;STRONG&gt;interview, the service(s) within the 6 months after initial interview, the 3 re-interview 5-7 months from the previous, and the service(s) delivered in between the re-interviews.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;- Client 004, and the same as above.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;2.Are you using SAS 9.4, this is important to me for me to attempt using more short cuts&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Answer:&lt;/U&gt;&amp;nbsp;Yes, I am using 9.4&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;3. I am doing you a favor by creating data have as follows:&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Answer:&lt;/U&gt;&lt;EM&gt;&amp;nbsp;&lt;/EM&gt;Thank you. This is my first posting ever, and I was so focus in&amp;nbsp;creating a good and well explained example of my issue that I forgot. I will try this does not happen in the future.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jan 2018 13:27:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429373#M13249</guid>
      <dc:creator>Asileon</dc:creator>
      <dc:date>2018-01-20T13:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observations between rows (same ID) and output the ID that meet the crite</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429374#M13250</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The original dataset has millions of observations, and in this example I used imaginary data. This dates represent month/day/year - &amp;nbsp;I used 01 as the day for all of the dates because I tried&amp;nbsp;to make it visually easy for the reader, I was attempting that the reader was able to see the time difference between dates without having to calculate too much.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jan 2018 13:32:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429374#M13250</guid>
      <dc:creator>Asileon</dc:creator>
      <dc:date>2018-01-20T13:32:09Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observations between rows (same ID) and output the ID that meet the crite</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429387#M13251</link>
      <description>&lt;P&gt;for the first criteria 001 also qualifies right because&amp;nbsp;&lt;STRONG&gt;07/01/2016&lt;/STRONG&gt; also within 6 months and this where I got confused. I am sorry, if this does not make sense.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;001&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;initial interview&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;02/01/2016&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;001&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;service delivered&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;&lt;STRONG&gt;07/01/2016&lt;/STRONG&gt;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;001&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;re-interview&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;08/01/2016&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;001&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;service delivered&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;10/01/2016&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Sat, 20 Jan 2018 15:52:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429387#M13251</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-01-20T15:52:57Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observations between rows (same ID) and output the ID that meet the crite</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429389#M13252</link>
      <description>&lt;P&gt;Thank you for the correction, you are right! I apologize, I was focused in including a possible qualify/ no-qualify situation for each client, and I did not do a good job with client 001. Please find below a fix for this, where client 001 DO NOT QUALIFY based on what I said before:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; have&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; ClientID Category &lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;20&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;Date&lt;/SPAN&gt; : mmddyy10&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;format&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;date&lt;/SPAN&gt; mmddyy10&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token keyword"&gt;datalines&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token data string"&gt;1	initial interview	2/1/2016
1	service delivered	&lt;STRONG&gt;8/25/2016&lt;/STRONG&gt;
1	re-interview	8/26/2016
1	service delivered	10/1/2016
1	re-interview	1/1/2017
1	service delivered	3/1/2017
1	re-interview	8/1/2017
2	initial interview	2/1/2016
2	service delivered	3/1/2016
2	re-interview	8/1/2016
2	service delivered	10/1/2016
2	re-interview	1/1/2017
2	service delivered	3/1/2017
2	re-interview	8/1/2017
3	initial interview	2/1/2016
3	re-interview	8/1/2016
3	service delivered	10/1/2016
3	re-interview	1/1/2017
3	service delivered	3/1/2017
3	re-interview	8/1/2017
4	initial interview	2/1/2016
4	service delivered	3/1/2016
4	re-interview	8/1/2016
4	service delivered	10/1/2016
4	re-interview	1/1/2017
4	service delivered	3/1/2017
4	re-interview	8/1/2017
4	service delivered	9/1/2017
4	re-interview	12/1/2017&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jan 2018 16:20:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429389#M13252</guid>
      <dc:creator>Asileon</dc:creator>
      <dc:date>2018-01-20T16:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observations between rows (same ID) and output the ID that meet the crite</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429390#M13253</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37783"&gt;@kiranv_&lt;/a&gt;&amp;nbsp;Please see response above, Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jan 2018 16:25:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429390#M13253</guid>
      <dc:creator>Asileon</dc:creator>
      <dc:date>2018-01-20T16:25:04Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observations between rows (same ID) and output the ID that meet the crite</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429394#M13254</link>
      <description>&lt;P&gt;Good morning from Chicago, Welcome to the SAS forum and thank you for the steadfast communication in clarifying. I'll be right back hopefully with the code or perhaps for some more clarifications.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jan 2018 16:59:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429394#M13254</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-20T16:59:37Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observations between rows (same ID) and output the ID that meet the crite</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429395#M13255</link>
      <description>Good morning!&lt;BR /&gt;&lt;BR /&gt;Thanks a lot &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;, I really appreciate it!&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 20 Jan 2018 17:10:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429395#M13255</guid>
      <dc:creator>Asileon</dc:creator>
      <dc:date>2018-01-20T17:10:13Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observations between rows (same ID) and output the ID that meet the crite</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429404#M13256</link>
      <description>&lt;P&gt;I question your logic regarding client 4. They had already met the criteria by the time they had their 3rd re-interview.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that is correct, then the following code (I think) captures all of your criteria:&lt;/P&gt;
&lt;PRE&gt;data have;
  infile datalines dlm=',';
  informat ClientID 8.;
  informat category $20.;
  informat date mmddyy10.;
  input ClientID Category Date;
  format date mmddyy10.;
  datalines;
1,initial interview,2/1/2016
1,service delivered,8/25/2016
1,re-interview,8/26/2016
1,service delivered,10/1/2016
1,re-interview,1/1/2017
1,service delivered,3/1/2017
1,re-interview,8/1/2017
2,initial interview,2/1/2016
2,service delivered,3/1/2016
2,re-interview,8/1/2016
2,service delivered,10/1/2016
2,re-interview,1/1/2017
2,service delivered,3/1/2017
2,re-interview,8/1/2017
3,initial interview,2/1/2016
3,re-interview,8/1/2016
3,service delivered,10/1/2016
3,re-interview,1/1/2017
3,service delivered,3/1/2017
3,re-interview,8/1/2017
4,initial interview,2/1/2016
4,service delivered,3/1/2016
4,re-interview,8/1/2016
4,service delivered,10/1/2016
4,re-interview,1/1/2017
4,service delivered,3/1/2017
4,re-interview,8/1/2017
4,service delivered,9/1/2017
4,re-interview,12/1/2017
;
/*
 Criterion1: initial interview (criterion_int)
 Criterion2: service within 6 months of initial interview
 Criterion3: 3 re-interviews within 5-7 months of each other,
              with each of the first two re-interviews
              followed by a service
*/
data want;
  set have;
  by ClientID;
  array reint(10);
  retain criterion1 criterion2 reint:;
  last_category=lag(category);
  last_date=lag(date);
  if first.ClientID then do;
    call missing(criterion1);
    call missing(criterion2);
    call missing(last_category);
    call missing(last_date);
    counter1=0;
    counter2=0;
  end;
  if category eq 'initial interview' then criterion1=date;
  else if not missing(criterion1) then do;
    if missing(criterion2) and category eq 'service delivered'
     and date le intnx('month',criterion1,6,'sameday')
     then criterion2=date;
    else if last_category eq 're-interview' and 
        category eq 'service delivered' then do;
         counter1+1;
         reint(counter1)=last_date;
    end;
    else if category eq 're-interview' and counter1 ge 2 then do;
       counter1+1;
       reint(counter1)=date;
    end;
  end;
  if last.ClientID and criterion1 and criterion2 and counter1 ge 3 then do;
    counter2=counter1;
    do i=1 to counter1-1;
      if not(intnx('month',reint(i),5,'sameday')&amp;lt;=
       reint(i+1)&amp;lt;=intnx('month',reint(i),7,'sameday')) then counter2=counter2-1;
    end;
  end;
  if counter2 ge 3;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jan 2018 19:58:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429404#M13256</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-01-20T19:58:48Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observations between rows (same ID) and output the ID that meet the crite</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429423#M13257</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ClientID Category &amp;amp; $20. Date : mmddyy10.;
format date mmddyy10.;
datalines;
1	initial interview	2/1/2016
1	service delivered	8/25/2016
1	re-interview	8/26/2016
1	service delivered	10/1/2016
1	re-interview	1/1/2017
1	service delivered	3/1/2017
1	re-interview	8/1/2017
2	initial interview	2/1/2016
2	service delivered	3/1/2016
2	re-interview	8/1/2016
2	service delivered	10/1/2016
2	re-interview	1/1/2017
2	service delivered	3/1/2017
2	re-interview	8/1/2017
3	initial interview	2/1/2016
3	re-interview	8/1/2016
3	service delivered	10/1/2016
3	re-interview	1/1/2017
3	service delivered	3/1/2017
3	re-interview	8/1/2017
4	initial interview	2/1/2016
4	service delivered	3/1/2016
4	re-interview	8/1/2016
4	service delivered	10/1/2016
4	re-interview	1/1/2017
4	service delivered	3/1/2017
4	re-interview	8/1/2017
4	service delivered	9/1/2017
4	re-interview	12/1/2017
;


/*I have a dataset with multiple observations per Client ID and have to select just the clients that meet the following criteria:

The client must have an initial interview.
The client must have at least one service 
(cleaning house, delivering groceries, etc.) delivered within 6 months of the initial interview.
The client must have at least 3 re-interviews 5-7 months apart from each other.
The client must have at least one service delivered between the re-interviews.
Get a final dataset with the qualifying Client ID and only the qualifying observations.*/


data want;
if _n_=1 then do; 
if 0 then set have(rename=(date=_date Category=_Category));
if 0 then set have(rename=(date=__date Category=__Category));
dcl hash h(dataset:'have(rename=(date=_date Category=_Category))', multidata: 'y');
 h.definekey('ClientID','_Category');
 h.definedata(all:'y');
 h.definedone();
 dcl hash h2(dataset:'have(rename=(date=__date Category=__Category))', multidata: 'y');
 h2.definekey('ClientID');
 h2.definedata(all:'y');
 h2.definedone();
 end;
 _qual=0;
 call missing(_count,_flag);
 do until(last.clientid);
 	set have;
 	by ClientID;
	if first.clientid and Category='initial interview' then 
		do;
 			do while(h2.do_over(key:ClientID) eq 0);
			if __Category='service delivered' and intck('month',date,__date)&amp;lt;6 then _qual=1;
			end;
		end;
	else if Category='re-interview' and _qual=1 then 
		do;
			if h.find(key:clientid,key:Category)=0 then 
				do;
					if 5&amp;lt;=intck('month',date,_date)&amp;lt;=7  then _count+1;
					rc = h.find_next();
					do while(rc = 0);
            			if 5&amp;lt;=intck('month',date,_date)&amp;lt;=7  then _count+1;
            			rc = h.find_next();
         			end;
					if _count&amp;gt;=3 then _qual=1;
				end;
		end;
	else  if Category='service delivered' and  _qual=1 then
		do;
			do while(h2.do_over(key:ClientID) eq 0);
			if  missing(_flag)and __Category='re-interview' and date&amp;gt;__date  then _holddate1=date;
			else if missing(_flag) and __Category='re-interview' and _holddate1&amp;lt;date then _flag=1;
			end;
			if _flag=1 then _qual=1;
		end;
	else _qual=0;
end;
do until(last.clientid);
	set have;
	by clientid;
	if _qual then output;
end;
drop _: rc;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 21 Jan 2018 00:03:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429423#M13257</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-21T00:03:50Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observations between rows (same ID) and output the ID that meet the crite</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429426#M13258</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;: Not a good use of the hash object. Your code takes more than four times longer than my straight forward datastep&amp;nbsp;to run! Plus, given the following example, your code fails to select ClientID 7.&lt;/P&gt;
&lt;PRE&gt;data have;
  infile datalines dlm=',';
  informat ClientID 8.;
  informat category $20.;
  informat date mmddyy10.;
  input ClientID Category Date;
  format date mmddyy10.;
  datalines;
1,initial interview,2/1/2016
1,service delivered,8/25/2016
1,re-interview,8/26/2016
1,service delivered,10/1/2016
1,re-interview,1/1/2017
1,service delivered,3/1/2017
1,re-interview,8/1/2017
2,initial interview,2/1/2016
2,service delivered,3/1/2016
2,re-interview,8/1/2016
2,service delivered,10/1/2016
2,re-interview,1/1/2017
2,service delivered,3/1/2017
2,re-interview,8/1/2017
3,initial interview,2/1/2016
3,re-interview,8/1/2016
3,service delivered,10/1/2016
3,re-interview,1/1/2017
3,service delivered,3/1/2017
3,re-interview,8/1/2017
4,initial interview,2/1/2016
4,service delivered,3/1/2016
4,re-interview,8/1/2016
4,service delivered,10/1/2016
4,re-interview,1/1/2017
4,service delivered,3/1/2017
4,re-interview,8/1/2017
4,service delivered,9/1/2017
4,re-interview,12/1/2017
5,initial interview,2/1/2016
5,service delivered,3/1/2016
5,re-interview,8/1/2016
5,service delivered,10/1/2016
5,re-interview,1/1/2017
5,service delivered,3/1/2017
5,re-interview,8/1/2017
6,initial interview,2/1/2016
6,service delivered,8/2/2016
6,re-interview,8/3/2016
6,service delivered,10/1/2016
6,re-interview,1/1/2017
6,service delivered,3/1/2017
6,re-interview,8/1/2017
7,initial interview,2/29/2016
7,service delivered,8/29/2016
7,re-interview,9/3/2016
7,service delivered,10/1/2016
7,re-interview,2/3/2017
7,service delivered,3/1/2017
7,re-interview,9/1/2017
;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jan 2018 01:01:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429426#M13258</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-01-21T01:01:37Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observations between rows (same ID) and output the ID that meet the crite</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429428#M13259</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot for your code!&lt;/P&gt;&lt;P&gt;That is correct, client 004 met the criteria by the third re-interview; all the clients will continue to have services and re-interviews, but I am interested in the initial interview, the following 3 re-interviews and the services within the initial interview/re-interviews.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will apply your code to my dataset, and let you know how it goes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!!&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jan 2018 01:50:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429428#M13259</guid>
      <dc:creator>Asileon</dc:creator>
      <dc:date>2018-01-21T01:50:09Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observations between rows (same ID) and output the ID that meet the crite</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429430#M13260</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your code! I will apply it to my dataset also, and see how it goes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jan 2018 01:55:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429430#M13260</guid>
      <dc:creator>Asileon</dc:creator>
      <dc:date>2018-01-21T01:55:43Z</dc:date>
    </item>
    <item>
      <title>Re: Counting the number of observations between rows (same ID) and output the ID that meet the crite</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429431#M13261</link>
      <description>&lt;P&gt;When hall of famers + Ksharp participate just go for their solution. However, I will work on an alternative to at least satisfy myself when i get to my college lab tomorrow. This forum is very addictive and yet because of whatever other factors my brain didn't seem to focus well enough today. Hmm, one of those days &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; lol&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I made a mistake in loop (&lt;STRONG&gt;do over associative array)&lt;/STRONG&gt;&amp;nbsp;too many times and that caused slow execution. I can make it to zip through a key only once and will find ways to match your requirement. Well, after all at least I try and proud to be a contributor here&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jan 2018 02:07:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Counting-the-number-of-observations-between-rows-same-ID-and/m-p/429431#M13261</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-21T02:07:26Z</dc:date>
    </item>
  </channel>
</rss>

