<?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: Looking at previous observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Looking-at-previous-observations/m-p/270084#M53611</link>
    <description>&lt;P&gt;Here's an easy way to read behind:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data samp_rd;&lt;BR /&gt; set samp nobs=nobs;&lt;BR /&gt; IF _N_ &amp;gt;= 2 then set samp(keep = indicator rename=(indicator=ind2));&lt;BR /&gt; IF _N_ &amp;gt;= 3 then Set samp (keep = indicator rename=(indicator=ind3));&lt;BR /&gt; put _all_;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It reads and renames the variable you're interested in first when you get to your second obs and then when you get to your 3rd obs.&lt;/P&gt;
&lt;P&gt;When indicator = ind2 = ind3 = 'Y' , you've found the condition you're looking for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;</description>
    <pubDate>Thu, 12 May 2016 14:25:34 GMT</pubDate>
    <dc:creator>BPD</dc:creator>
    <dc:date>2016-05-12T14:25:34Z</dc:date>
    <item>
      <title>Looking at previous observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looking-at-previous-observations/m-p/269934#M53539</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to do the following but I'm not sure how to look at the previous observations.&lt;/P&gt;&lt;P&gt;My data:&lt;/P&gt;&lt;P&gt;Month &amp;nbsp; ID &amp;nbsp; Indicator&lt;/P&gt;&lt;P&gt;Jan &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y&lt;/P&gt;&lt;P&gt;Feb &amp;nbsp; &amp;nbsp; &amp;nbsp; A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;N&lt;/P&gt;&lt;P&gt;Mar &amp;nbsp; &amp;nbsp; &amp;nbsp; A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y&lt;/P&gt;&lt;P&gt;Apr &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y&lt;/P&gt;&lt;P&gt;May &amp;nbsp; &amp;nbsp; &amp;nbsp;A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y&lt;/P&gt;&lt;P&gt;June &amp;nbsp; &amp;nbsp; A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;N&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I am trying to do is that, if there are 3 consecutive Y indicators in consecutive months for the same ID, then in that month, it will be a BAD.&amp;nbsp;I have already sorted by ID (there will be other IDs in the same months as well), but cannot think of ways to use first. and last. in this case.&amp;nbsp;&lt;/P&gt;&lt;P&gt;My output will be:&lt;/P&gt;&lt;P&gt;Month &amp;nbsp; ID &amp;nbsp; Indicator &amp;nbsp;Quality&lt;/P&gt;&lt;P&gt;Jan &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Good&lt;/P&gt;&lt;P&gt;Feb &amp;nbsp; &amp;nbsp; &amp;nbsp; A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;N &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Good&lt;/P&gt;&lt;P&gt;Mar &amp;nbsp; &amp;nbsp; &amp;nbsp; A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Good&lt;/P&gt;&lt;P&gt;Apr &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Y &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Good&lt;/P&gt;&lt;P&gt;May &amp;nbsp; &amp;nbsp; &amp;nbsp;A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Y &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;BAD&lt;/P&gt;&lt;P&gt;June &amp;nbsp; &amp;nbsp; A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;N &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Good&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope you guys will be able to guide me on how to do this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2016 02:42:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looking-at-previous-observations/m-p/269934#M53539</guid>
      <dc:creator>LaiQ</dc:creator>
      <dc:date>2016-05-12T02:42:49Z</dc:date>
    </item>
    <item>
      <title>Re: Looking at previous observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looking-at-previous-observations/m-p/269936#M53540</link>
      <description>&lt;P&gt;Here's a way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by ID;&lt;/P&gt;
&lt;P&gt;if first.ID then count=0;&lt;/P&gt;
&lt;P&gt;if indicator='N' then count=0;&lt;/P&gt;
&lt;P&gt;else count + 1;&lt;/P&gt;
&lt;P&gt;if count &amp;lt; 3 quality='Good';&lt;/P&gt;
&lt;P&gt;else quality='BAD';&lt;/P&gt;
&lt;P&gt;drop count;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2016 02:47:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looking-at-previous-observations/m-p/269936#M53540</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-05-12T02:47:40Z</dc:date>
    </item>
    <item>
      <title>Re: Looking at previous observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looking-at-previous-observations/m-p/269945#M53542</link>
      <description>&lt;P&gt;Assuming there are not gap(missing month) in MONTH variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;CODE NOT TESTED.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;set have;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;Quality='GOOD';&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;if id=lag(id) and id=lag2(id) and&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;SPAN&gt;Indicator ='Y' and lag(Indicator )='Y' and lag2(Indicator )='Y' then&amp;nbsp;Quality='BAD';&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2016 03:21:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looking-at-previous-observations/m-p/269945#M53542</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-05-12T03:21:59Z</dc:date>
    </item>
    <item>
      <title>Re: Looking at previous observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looking-at-previous-observations/m-p/270006#M53569</link>
      <description>Thank you! Really appreciate it! &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;</description>
      <pubDate>Thu, 12 May 2016 09:54:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looking-at-previous-observations/m-p/270006#M53569</guid>
      <dc:creator>LaiQ</dc:creator>
      <dc:date>2016-05-12T09:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: Looking at previous observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looking-at-previous-observations/m-p/270008#M53570</link>
      <description>Will try it, thank you too!</description>
      <pubDate>Thu, 12 May 2016 09:57:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looking-at-previous-observations/m-p/270008#M53570</guid>
      <dc:creator>LaiQ</dc:creator>
      <dc:date>2016-05-12T09:57:14Z</dc:date>
    </item>
    <item>
      <title>Re: Looking at previous observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Looking-at-previous-observations/m-p/270084#M53611</link>
      <description>&lt;P&gt;Here's an easy way to read behind:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data samp_rd;&lt;BR /&gt; set samp nobs=nobs;&lt;BR /&gt; IF _N_ &amp;gt;= 2 then set samp(keep = indicator rename=(indicator=ind2));&lt;BR /&gt; IF _N_ &amp;gt;= 3 then Set samp (keep = indicator rename=(indicator=ind3));&lt;BR /&gt; put _all_;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It reads and renames the variable you're interested in first when you get to your second obs and then when you get to your 3rd obs.&lt;/P&gt;
&lt;P&gt;When indicator = ind2 = ind3 = 'Y' , you've found the condition you're looking for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;</description>
      <pubDate>Thu, 12 May 2016 14:25:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Looking-at-previous-observations/m-p/270084#M53611</guid>
      <dc:creator>BPD</dc:creator>
      <dc:date>2016-05-12T14:25:34Z</dc:date>
    </item>
  </channel>
</rss>

