<?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: Returning values in Three Consecutive Months in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Returning-values-in-Three-Consecutive-Months/m-p/178862#M34189</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by person;&lt;BR /&gt;Mon=month(input(catt(Month,year),monyy7.));&lt;BR /&gt;lg=mon-lag(mon);&lt;BR /&gt;if first.person then cnt=1;&lt;BR /&gt;if not first.person and lg&amp;gt;1 then cnt+1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select person,claim,month,year from want&lt;BR /&gt;group by person,cnt&lt;BR /&gt;having count(distinct mon)=3&lt;BR /&gt;order by person, claim;&lt;BR /&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 28 Aug 2014 20:06:11 GMT</pubDate>
    <dc:creator>stat_sas</dc:creator>
    <dc:date>2014-08-28T20:06:11Z</dc:date>
    <item>
      <title>Returning values in Three Consecutive Months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returning-values-in-Three-Consecutive-Months/m-p/178861#M34188</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a data set with a bunch of people in it, each of whom have different claims at different times.&amp;nbsp; I need a code to return all claims which are billed for three consecutive months for that particular person.&amp;nbsp; For example, I have the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid rgb(0, 0, 0); width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Person&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;Claim&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Month&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Year&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Mar&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2013&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Apr&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2013&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;3&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;May&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2013&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;4&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Aug&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2014&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;B&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;5&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Sep&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2012&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;B&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;6&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Oct&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2012&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD colspan="1"&gt;B&lt;/TD&gt;&lt;TD colspan="1"&gt;7&lt;/TD&gt;&lt;TD colspan="1"&gt;Oct&lt;/TD&gt;&lt;TD colspan="1"&gt;2012&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;C&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;8&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;Dec&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;2013&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I basically just need to it return the 'Claim' values of 1, 2, and 3 since person A billed in three consecutive months.&amp;nbsp; How would I do this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Much appreciated.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Aug 2014 15:24:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returning-values-in-Three-Consecutive-Months/m-p/178861#M34188</guid>
      <dc:creator>OMGlob</dc:creator>
      <dc:date>2014-08-28T15:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: Returning values in Three Consecutive Months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returning-values-in-Three-Consecutive-Months/m-p/178862#M34189</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by person;&lt;BR /&gt;Mon=month(input(catt(Month,year),monyy7.));&lt;BR /&gt;lg=mon-lag(mon);&lt;BR /&gt;if first.person then cnt=1;&lt;BR /&gt;if not first.person and lg&amp;gt;1 then cnt+1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;select person,claim,month,year from want&lt;BR /&gt;group by person,cnt&lt;BR /&gt;having count(distinct mon)=3&lt;BR /&gt;order by person, claim;&lt;BR /&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Aug 2014 20:06:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returning-values-in-Three-Consecutive-Months/m-p/178862#M34189</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2014-08-28T20:06:11Z</dc:date>
    </item>
    <item>
      <title>Re: Returning values in Three Consecutive Months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returning-values-in-Three-Consecutive-Months/m-p/178863#M34190</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Suppose they have 5 consecutive months. Which 3 do you want included, first 3, middle 3 or last 3?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Aug 2014 20:38:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returning-values-in-Three-Consecutive-Months/m-p/178863#M34190</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-08-28T20:38:36Z</dc:date>
    </item>
    <item>
      <title>Re: Returning values in Three Consecutive Months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returning-values-in-Three-Consecutive-Months/m-p/178864#M34191</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ballardw, I would like it to include all five months in that case.&amp;nbsp; They just have to have at least three.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Stat@SAS, thanks, I will try that code at work tomorrow.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Aug 2014 22:21:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returning-values-in-Three-Consecutive-Months/m-p/178864#M34191</guid>
      <dc:creator>OMGlob</dc:creator>
      <dc:date>2014-08-28T22:21:54Z</dc:date>
    </item>
    <item>
      <title>Re: Returning values in Three Consecutive Months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returning-values-in-Three-Consecutive-Months/m-p/178865#M34192</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is mostly working, but I don't think it's taking years into account years.&amp;nbsp; Defining the Mon variable, Oct 2012 and Oct 2013 have the same value, no?&amp;nbsp; How do I account for this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Aug 2014 13:33:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returning-values-in-Three-Consecutive-Months/m-p/178865#M34192</guid>
      <dc:creator>OMGlob</dc:creator>
      <dc:date>2014-08-29T13:33:40Z</dc:date>
    </item>
    <item>
      <title>Re: Returning values in Three Consecutive Months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returning-values-in-Three-Consecutive-Months/m-p/178866#M34193</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;data have;
input (person claim month year ) ( : $40.);
date=input(cats('01',month,year),date9.);
format date date9.;
cards;
A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Mar&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2013
A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Apr&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2013
A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;May&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2013
A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Aug&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2014
B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Sep&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2012
B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Oct&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2012
B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Oct&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2012
C&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dec&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2013
;
run;

data temp;
 set have;
 if lag(person) eq person and intck('month',lag(date),date)=1 then do;
&amp;nbsp; lag_n=_n_-1;
&amp;nbsp; set have point=lag_n ;output;
&amp;nbsp; set have point=_n_ ;output;
end;
run;
proc sql;
create table want as
 select * from (select distinct * from temp)
&amp;nbsp; group by person
&amp;nbsp;&amp;nbsp; having count(*) gt 2 ;
quit;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Aug 2014 13:58:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returning-values-in-Three-Consecutive-Months/m-p/178866#M34193</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-08-29T13:58:03Z</dc:date>
    </item>
    <item>
      <title>Re: Returning values in Three Consecutive Months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returning-values-in-Three-Consecutive-Months/m-p/178867#M34194</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Something like this (assuming the dataset is sorted):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input Person $ Claim Month $ Year ;&lt;BR /&gt;datalines;&lt;BR /&gt;A 1 Mar 2013 &lt;BR /&gt;A 2 Apr 2013 &lt;BR /&gt;A 3 May 2013 &lt;BR /&gt;A 4 Aug 2014 &lt;BR /&gt;A 5 Sep 2014&lt;BR /&gt;A 6 Oct 2014&lt;BR /&gt;A 7 Nov 2014&lt;BR /&gt;A 8 Dec 2014&lt;BR /&gt;A 9 Jan 2015&lt;BR /&gt;B 5 Sep 2012 &lt;BR /&gt;B 6 Oct 2012 &lt;BR /&gt;B 7 Nov 2013 &lt;BR /&gt;C 8 Dec 2013 &lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by person;&lt;/P&gt;&lt;P&gt;retain flag;&lt;/P&gt;&lt;P&gt;put flag "after";&lt;/P&gt;&lt;P&gt;curmonth=month(input(cats(month,year),monyy7.));&lt;BR /&gt;prevmonth=month(input(cats((lag(month)),lag(year)),monyy7.));&lt;BR /&gt;curdate=mdy(curmonth,1,year);&lt;BR /&gt;prevdate=intnx('month',mdy(prevmonth,1,lag(year)),1);&lt;/P&gt;&lt;P&gt;if first.person then flag=1;&lt;BR /&gt;else if curdate=prevdate then flag+1;&lt;BR /&gt;else flag=1;&lt;/P&gt;&lt;P&gt;if flag gt 3 then flag=1; &lt;/P&gt;&lt;P&gt;drop cur: prev:;&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Aug 2014 14:24:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returning-values-in-Three-Consecutive-Months/m-p/178867#M34194</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2014-08-29T14:24:18Z</dc:date>
    </item>
  </channel>
</rss>

