<?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 consecutive months in sas in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/counting-consecutive-months-in-sas/m-p/768977#M243927</link>
    <description>thanks, the result shows each member and most recent month, but not the total count of consecutive months.</description>
    <pubDate>Tue, 21 Sep 2021 23:55:39 GMT</pubDate>
    <dc:creator>yunnieling</dc:creator>
    <dc:date>2021-09-21T23:55:39Z</dc:date>
    <item>
      <title>counting consecutive months in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/counting-consecutive-months-in-sas/m-p/768972#M243923</link>
      <description>&lt;P&gt;From the sample data below, I'm trying to count how many consecutive months a member has. In the event if an ID has a gap month in the middle, the output should show the most recent count of consecutive months this member had, see example below.&lt;/P&gt;&lt;P&gt;dataset=one&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="s-table-container"&gt;ID Month &lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;72&lt;/TD&gt;&lt;TD&gt;01SEP2020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;72&lt;/TD&gt;&lt;TD&gt;01OCT2020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;72&lt;/TD&gt;&lt;TD&gt;01NOV2020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;72&lt;/TD&gt;&lt;TD&gt;01DEC2020&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;72&lt;/TD&gt;&lt;TD&gt;01FEB2021&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;72&lt;/TD&gt;&lt;TD&gt;01MAR2021&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;72&lt;/TD&gt;&lt;TD&gt;01APR2021&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;72&lt;/TD&gt;&lt;TD&gt;01MAY2021&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;72&lt;/TD&gt;&lt;TD&gt;01JUN2021&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;&lt;P&gt;desired output is as follows:&lt;/P&gt;&lt;DIV class="s-table-container"&gt;ID months_ct &lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;72&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 21 Sep 2021 23:33:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/counting-consecutive-months-in-sas/m-p/768972#M243923</guid>
      <dc:creator>yunnieling</dc:creator>
      <dc:date>2021-09-21T23:33:19Z</dc:date>
    </item>
    <item>
      <title>Re: counting consecutive months in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/counting-consecutive-months-in-sas/m-p/768975#M243926</link>
      <description>&lt;P&gt;If the data are sorted by id/month and month is stored as a sas date value, then:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by id;
  if first.id=1 or intck('month',lag(month),month)^=1 then consec_months=1;
  else consec_months+1;
  if last.id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Sep 2021 23:41:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/counting-consecutive-months-in-sas/m-p/768975#M243926</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-09-21T23:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: counting consecutive months in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/counting-consecutive-months-in-sas/m-p/768977#M243927</link>
      <description>thanks, the result shows each member and most recent month, but not the total count of consecutive months.</description>
      <pubDate>Tue, 21 Sep 2021 23:55:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/counting-consecutive-months-in-sas/m-p/768977#M243927</guid>
      <dc:creator>yunnieling</dc:creator>
      <dc:date>2021-09-21T23:55:39Z</dc:date>
    </item>
    <item>
      <title>Re: counting consecutive months in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/counting-consecutive-months-in-sas/m-p/768979#M243928</link>
      <description>&lt;P&gt;Please show the log when describing unexpected results.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 00:03:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/counting-consecutive-months-in-sas/m-p/768979#M243928</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-09-22T00:03:21Z</dc:date>
    </item>
    <item>
      <title>Re: counting consecutive months in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/counting-consecutive-months-in-sas/m-p/768980#M243929</link>
      <description>Log:26&lt;BR /&gt;27 data want;&lt;BR /&gt;28 set idk;&lt;BR /&gt;29 by eci_id ;&lt;BR /&gt;30 if first.eci_id=1 or intck('month',lag(inc_mth_dt),month)^=1 then consec_months=1;&lt;BR /&gt;31 else consec_months+1;&lt;BR /&gt;32 if last.eci_id;&lt;BR /&gt;33 run;&lt;BR /&gt;&lt;BR /&gt;NOTE: Variable month is uninitialized.&lt;BR /&gt;NOTE: Missing values were generated as a result of performing an operation on missing values.&lt;BR /&gt;Each place is given by: (Number of times) at (Line):(Column).&lt;BR /&gt;4162545 at 30:24&lt;BR /&gt;NOTE: There were 4162545 observations read from the data set WORK.IDK.&lt;BR /&gt;NOTE: The data set WORK.WANT has 65205 observations and 4 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;real time 0.35 seconds&lt;BR /&gt;cpu time 0.35 seconds&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Below is the result.&lt;BR /&gt;ECI_ID INC_MTH_DT month consec_months&lt;BR /&gt;72 01SEP2021 . 1&lt;BR /&gt;125 01SEP2021 . 1&lt;BR /&gt;203 01SEP2021 . 1&lt;BR /&gt;325 01SEP2021 . 1&lt;BR /&gt;329 01SEP2021 . 1&lt;BR /&gt;371 01OCT2020 . 1&lt;BR /&gt;438 01SEP2021 . 1&lt;BR /&gt;466 01MAY2019 . 1</description>
      <pubDate>Wed, 22 Sep 2021 00:08:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/counting-consecutive-months-in-sas/m-p/768980#M243929</guid>
      <dc:creator>yunnieling</dc:creator>
      <dc:date>2021-09-22T00:08:16Z</dc:date>
    </item>
    <item>
      <title>Re: counting consecutive months in sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/counting-consecutive-months-in-sas/m-p/768981#M243930</link>
      <description>&lt;P&gt;Please read the documentation on the INTCK and LAG functions, then complete your modification of the&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;intck('month',lag(inc_mth_dt),month)&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;expression.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Sep 2021 00:23:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/counting-consecutive-months-in-sas/m-p/768981#M243930</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-09-22T00:23:59Z</dc:date>
    </item>
  </channel>
</rss>

