<?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: Flagging two consecutive decreases in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/334499#M75543</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Well, I need to flag the first month, at which we see two consequtive decreases and retain it until the last record for each patient, regardless future increases. Does this make sense?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;MK&lt;/P&gt;</description>
    <pubDate>Mon, 20 Feb 2017 23:00:43 GMT</pubDate>
    <dc:creator>MiraKr_</dc:creator>
    <dc:date>2017-02-20T23:00:43Z</dc:date>
    <item>
      <title>Flagging two consecutive decreases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/334491#M75540</link>
      <description>&lt;P&gt;Hi--,&lt;/P&gt;
&lt;P&gt;I need to flag the first record among two consequitve decreases in MMSE. I provide the dataset that I have and the dataset that I would like to achieve. Please help me if you can!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data Have;&lt;BR /&gt;input patnum mmse month;&lt;BR /&gt;datalines;&lt;BR /&gt;101 28 0&lt;BR /&gt;101 28 6&lt;BR /&gt;101 29 36&lt;BR /&gt;101 28 60&lt;BR /&gt;101 25.7 66&lt;BR /&gt;101 23 72&lt;BR /&gt;101 24 78&lt;BR /&gt;101 24.5 84&lt;BR /&gt;102 29 0&lt;BR /&gt;102 28 6&lt;BR /&gt;102 28 36&lt;BR /&gt;102 27 60 &lt;BR /&gt;102 29 66 &lt;BR /&gt;102 28 72 &lt;BR /&gt;102 27 72 &lt;BR /&gt;102 26 78 &lt;BR /&gt;102 26 84 &lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data Want;&lt;BR /&gt;input patnum mmse month re_month;&lt;BR /&gt;datalines;&lt;BR /&gt;101 28 0 . &lt;BR /&gt;101 28 6 . &lt;BR /&gt;101 29 36 . &lt;BR /&gt;101 28 60 60&lt;BR /&gt;101 25.7 66 60&lt;BR /&gt;101 23 72 60&lt;BR /&gt;101 24 78 60&lt;BR /&gt;101 24.5 84 60&lt;BR /&gt;102 29 0 . &lt;BR /&gt;102 28 6 . &lt;BR /&gt;102 28 36 . &lt;BR /&gt;102 27 60 .&lt;BR /&gt;102 29 66 . &lt;BR /&gt;102 28 72 72 &lt;BR /&gt;102 27 72 72 &lt;BR /&gt;102 26 78 72 &lt;BR /&gt;102 26 84 72&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;MK&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2017 22:45:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/334491#M75540</guid>
      <dc:creator>MiraKr_</dc:creator>
      <dc:date>2017-02-20T22:45:57Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging two consecutive decreases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/334497#M75541</link>
      <description>&lt;P&gt;Why are the following listed as decreases:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;101 24 78 60&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;101 24.5 84 60&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2017 22:56:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/334497#M75541</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-20T22:56:39Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging two consecutive decreases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/334499#M75543</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Well, I need to flag the first month, at which we see two consequtive decreases and retain it until the last record for each patient, regardless future increases. Does this make sense?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;MK&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2017 23:00:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/334499#M75543</guid>
      <dc:creator>MiraKr_</dc:creator>
      <dc:date>2017-02-20T23:00:43Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging two consecutive decreases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/334500#M75544</link>
      <description>&lt;P&gt;I've interpreted this as setting re_month as being persistant from where the two consecutive decreasing values started. Is this what you want?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data decrease;
set have;
by patnum;
save_month = lag1(month);
if patnum = lag2(patnum)
 &amp;amp; mmse &amp;lt; lag1(mmse)
 &amp;amp; lag1(mmse) &amp;lt; lag2(mmse) then
   output;
keep patnum save_month;
rename save_month = month;
run;

data decrease;
set decrease;
by patnum;
if first.patnum;
run;

proc sql;
create table want as
   select have.*,
          decrease.month as re_month
     from have
     left join decrease
       on have.patnum = decrease.patnum
      and have.month &amp;gt;= decrease.month
    order by have.patnum,
             have.month;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2017 23:05:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/334500#M75544</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-02-20T23:05:41Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging two consecutive decreases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/334502#M75545</link>
      <description>&lt;P&gt;Hi&amp;nbsp; &lt;SPAN class="login-bold"&gt;&lt;A id="link_8" class="lia-link-navigation lia-page-link lia-user-name-link" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17429" target="_self"&gt;LaurieF&lt;/A&gt;,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="login-bold"&gt;Yes, this seems to produce what I need. Thank you so much for the quick solution &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; I will apply it to the bigger dataset now and check if it works there too.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2017 23:11:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/334502#M75545</guid>
      <dc:creator>MiraKr_</dc:creator>
      <dc:date>2017-02-20T23:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging two consecutive decreases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/334503#M75546</link>
      <description>&lt;P&gt;I think the following would run more quickly:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want (drop=_:);
  set have;
  retain re_month;
  by patnum;
  if first.patnum then call missing(re_month);
  _mmse0=lag(mmse);
  if missing(re_month) and not last.patnum then do;
    _n_+1;
    set have (keep=mmse rename=(mmse=_mmse1)) point=_n_;
    if _mmse1&amp;lt;mmse&amp;lt;_mmse0 then re_month=month;
  end;
run;
&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 Feb 2017 23:19:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/334503#M75546</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-20T23:19:22Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging two consecutive decreases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/334506#M75548</link>
      <description>&lt;P&gt;Hi&amp;nbsp; &lt;SPAN class="login-bold"&gt;&lt;A id="link_9" class="lia-link-navigation lia-page-link lia-user-name-link" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711" target="_self"&gt;art297&lt;/A&gt;,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="login-bold"&gt;Thank you so much! I will try this solution as well.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Feb 2017 23:33:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/334506#M75548</guid>
      <dc:creator>MiraKr_</dc:creator>
      <dc:date>2017-02-20T23:33:22Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging two consecutive decreases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/334546#M75565</link>
      <description>&lt;P&gt;Hi art297,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to ask you a small question regarding the code that you posted:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;what is the _n_+1 ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;does it crete a lag, in the sense that if&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;missing(re_month) and not last.patnum&lt;/PRE&gt;
&lt;P&gt;for a certain observation then you set the data set have of the next observation (i.e observation#+1) and then to this new observation you do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;if _mmse1&amp;lt;mmse&amp;lt;_mmse0 then re_month=month;&lt;/PRE&gt;
&lt;P&gt;Also, what does "point=_n_" exactly do?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 03:33:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/334546#M75565</guid>
      <dc:creator>ilikesas</dc:creator>
      <dc:date>2017-02-21T03:33:53Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging two consecutive decreases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/334558#M75570</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12982"&gt;@ilikesas&lt;/a&gt;: I like to use _n_ as it is an automatic variable that doesn't appear in one's dataset and doesn't have to be dropped.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is the same _n_ that informs you of which record you are currently working on, and using it doesn't have any adverse effect on its intended use. So, at the beginning of processing the 20th record in a file, _n_ will still be equal to 20.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used it, in the above code, as a variable that would represent the extra record I want to process. Thus, by stating:&lt;/P&gt;
&lt;PRE&gt;    _n_+1;
    set have (keep=mmse rename=(mmse=_mmse1)) point=_n_;
&lt;/PRE&gt;
&lt;P&gt;it brings in the NEXT record so that we can see, in this case, if there was a decrease. When we're processing the 10th record, _n_ will be equal to 10, _n_+1 will be equal to 11.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 04:30:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/334558#M75570</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-21T04:30:47Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging two consecutive decreases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/334594#M75579</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;, that code is so cunning, you could pin a tail on it and call it a weasel. I'm very impressed.&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 09:02:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/334594#M75579</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-02-21T09:02:02Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging two consecutive decreases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/334632#M75592</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17429"&gt;@LaurieF&lt;/a&gt;: I can't take credit for it .. I stole it from Howard Schreier years ago. He provides various look ahead/look back&amp;nbsp;methods at:&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www.sascommunity.org/wiki/Look-Ahead_and_Look-Back" target="_blank"&gt;http://www.sascommunity.org/wiki/Look-Ahead_and_Look-Back&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In fact, my code was more&amp;nbsp;cumbersome than it had to be&amp;nbsp;and could have been shortened to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want (drop=_:);
  set have;
  retain re_month;
  by patnum;
  set have ( firstobs = 2 keep=mmse rename=(mmse=_mmse1))
      have (      obs = 1 drop = _all_                  );
  if first.patnum then call missing(re_month);
  _mmse0=lag(mmse);
  if missing(re_month) and not last.patnum then
   if _mmse1&amp;lt;mmse&amp;lt;_mmse0 then re_month=month;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 12:51:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/334632#M75592</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-21T12:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging two consecutive decreases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/334668#M75595</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN class="login-bold"&gt;&lt;A id="link_8" class="lia-link-navigation lia-page-link lia-user-name-link" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711" target="_self"&gt;art297&lt;/A&gt;&amp;nbsp;and&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17429" target="_blank"&gt;LaurieF&lt;/A&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I provide a slightly edited HAVE dataset, for which the SAS program by art297 doesn't seem to work well. For patient 103, the flag should be at 72 months. &amp;nbsp;Instead, it flags month 0.&amp;nbsp;I am not sure if there would be an easy fix?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data Have;&lt;BR /&gt;input patnum mmse month;&lt;BR /&gt;datalines;&lt;BR /&gt;101 28 0&lt;BR /&gt;101 28 6&lt;BR /&gt;101 29 36&lt;BR /&gt;101 28 60&lt;BR /&gt;101 25.7 66&lt;BR /&gt;101 23 72&lt;BR /&gt;101 24 78&lt;BR /&gt;101 24.5 84&lt;BR /&gt;102 29 0&lt;BR /&gt;102 28 6&lt;BR /&gt;102 28 36&lt;BR /&gt;102 27 60 &lt;BR /&gt;102 29 66 &lt;BR /&gt;102 28 72 &lt;BR /&gt;102 27 78 &lt;BR /&gt;102 26 84 &lt;BR /&gt;102 27 90&lt;BR /&gt;103 25 0&lt;BR /&gt;103 24 6 &lt;BR /&gt;103 28 36 &lt;BR /&gt;103 27 60&lt;BR /&gt;103 29 66 &lt;BR /&gt;103 28 72 &lt;BR /&gt;103 26 78 &lt;BR /&gt;103 25 84 &lt;BR /&gt;103 28 90 &lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code by&amp;nbsp;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17429" target="_blank"&gt;LaurieF&lt;/A&gt;&amp;nbsp;works fine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Again, thank you both for your inputs!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 14:57:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/334668#M75595</guid>
      <dc:creator>MiraKr_</dc:creator>
      <dc:date>2017-02-21T14:57:24Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging two consecutive decreases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/334678#M75596</link>
      <description>&lt;P&gt;Yes, easy fix to the code I suggested:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want (drop=_:);
  set have;
  retain re_month;
  by patnum;
  set have ( firstobs = 2 keep=mmse rename=(mmse=_mmse1))
      have (      obs = 1 drop = _all_                  );
  _mmse0=lag(mmse);
  if first.patnum then call missing(re_month);
  else if missing(re_month) and not last.patnum then
   if _mmse1&amp;lt;mmse&amp;lt;_mmse0 then re_month=month;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Feb 2017 15:18:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/334678#M75596</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-21T15:18:10Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging two consecutive decreases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/337109#M76505</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;
&lt;P&gt;Thank you for helping me the first time. If it is okay, I would like to ask for one more task, which I've been struggling for a couple of hours now. My client now wants to do another exploratry step, where we flag and retain the first month the outcome measure (mmse) drops below the threshold of 28 and never comes back up to that threshold. If a patient dropped below the threshold, went back up and then dropped again, I am supposed to flag the fist time of the last drop. Ultimately, I am trying to get to dataset "WANT_SHORT", but I suppose that I need to first get to "WANT_LONG" and then output the last patient observation to get to WANT_SHORT. &amp;nbsp;I will really appreciate it if you can help me with this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data Want_long;&lt;BR /&gt;input patnum mmse month re_month;&lt;BR /&gt;datalines;&lt;BR /&gt;101 28 0 .&lt;BR /&gt;101 28 6 .&lt;BR /&gt;101 29 36 .&lt;BR /&gt;101 28 60 .&lt;BR /&gt;101 25.7 66 66 &lt;BR /&gt;101 23 72 66 &lt;BR /&gt;101 24 78 66 &lt;BR /&gt;101 24.5 84 66&lt;BR /&gt;102 29 0 .&lt;BR /&gt;102 28 6 .&lt;BR /&gt;102 28 36 .&lt;BR /&gt;102 27 60 . &lt;BR /&gt;102 29 66 . &lt;BR /&gt;102 28 72 . &lt;BR /&gt;102 27 78 78&lt;BR /&gt;102 26 84 78&lt;BR /&gt;102 27 90 78&lt;BR /&gt;103 25 0 .&lt;BR /&gt;103 24 6 . &lt;BR /&gt;103 28 36 . &lt;BR /&gt;103 27 60 .&lt;BR /&gt;103 29 66 . &lt;BR /&gt;103 28 72 . &lt;BR /&gt;103 26 78 . &lt;BR /&gt;103 25 84 . &lt;BR /&gt;103 28 90 . &lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data Want_short;&lt;BR /&gt;input patnum mmse month re_month;&lt;BR /&gt;datalines;&lt;BR /&gt;101 24.5 84 66&lt;BR /&gt;102 27 90 78&lt;BR /&gt;103 28 90 .&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;MK&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2017 19:22:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/337109#M76505</guid>
      <dc:creator>MiraKr_</dc:creator>
      <dc:date>2017-03-01T19:22:36Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging two consecutive decreases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/337119#M76512</link>
      <description>&lt;P&gt;If this is what you want, you owe me a beer:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table below as
   select h.patnum, 
          h.month as re_month
     from have as h
     left join have as above
       on h.patnum = above.patnum
      and above.mmse ge 28
      and h.month &amp;lt; above.month
    where h.mmse &amp;lt; 28
      and above.month is null
    order by h.patnum,
             h.month;
quit;

data below;
set below;
by patnum;
if first.patnum;
run;

data want;
merge have
      below;
by patnum;
if last.patnum;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This generates your&amp;nbsp;&lt;EM&gt;want_shor&lt;/EM&gt;&lt;EM&gt;t.&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2017 20:05:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/337119#M76512</guid>
      <dc:creator>LaurieF</dc:creator>
      <dc:date>2017-03-01T20:05:52Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging two consecutive decreases</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/337133#M76519</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN class="login-bold"&gt;&lt;A id="link_8" class="lia-link-navigation lia-page-link lia-user-name-link" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/17429" target="_self"&gt;LaurieF&lt;/A&gt;,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="login-bold"&gt;This works perfectly!! Thanks so much! I am trying to understand how the code works and may come back with questions. You really saved me here because I have to run these summaries for multiple thresholds and outcomes (not just mmse) on long datasets and it is all due in a very short amount of time!&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="login-bold"&gt;I do owe you a beer!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="login-bold"&gt;Cheers!&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2017 20:23:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-two-consecutive-decreases/m-p/337133#M76519</guid>
      <dc:creator>MiraKr_</dc:creator>
      <dc:date>2017-03-01T20:23:45Z</dc:date>
    </item>
  </channel>
</rss>

