<?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 array to look up value from the previous record in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/array-to-look-up-value-from-the-previous-record/m-p/123968#M25402</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i created this output below using couple datasteps with arrays.&amp;nbsp; I'm struggling to do the following: return the ID number where the value increases month-over-month. In the example given below the output would be ID 16 (since in april12 it had gone up to 114 from 100)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm writing this in VBA without any issues, since the code loop through cells and compare the values from the previous record using index functions. I'm struggling transitioning this to SAS. any help is much appreciated.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; Month Score&lt;/P&gt;&lt;P&gt;16 Jan12 112&lt;/P&gt;&lt;P&gt;16 Feb12 110&lt;/P&gt;&lt;P&gt;16 March12 100&lt;/P&gt;&lt;P&gt;16 April12 114&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;35 Jan12 120&lt;/P&gt;&lt;P&gt;35 Feb12 115&lt;/P&gt;&lt;P&gt;35 March 106&lt;/P&gt;&lt;P&gt;35 April 100&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 01 Jul 2013 21:20:48 GMT</pubDate>
    <dc:creator>chayo</dc:creator>
    <dc:date>2013-07-01T21:20:48Z</dc:date>
    <item>
      <title>array to look up value from the previous record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-to-look-up-value-from-the-previous-record/m-p/123968#M25402</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i created this output below using couple datasteps with arrays.&amp;nbsp; I'm struggling to do the following: return the ID number where the value increases month-over-month. In the example given below the output would be ID 16 (since in april12 it had gone up to 114 from 100)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm writing this in VBA without any issues, since the code loop through cells and compare the values from the previous record using index functions. I'm struggling transitioning this to SAS. any help is much appreciated.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; Month Score&lt;/P&gt;&lt;P&gt;16 Jan12 112&lt;/P&gt;&lt;P&gt;16 Feb12 110&lt;/P&gt;&lt;P&gt;16 March12 100&lt;/P&gt;&lt;P&gt;16 April12 114&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;35 Jan12 120&lt;/P&gt;&lt;P&gt;35 Feb12 115&lt;/P&gt;&lt;P&gt;35 March 106&lt;/P&gt;&lt;P&gt;35 April 100&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Jul 2013 21:20:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-to-look-up-value-from-the-previous-record/m-p/123968#M25402</guid>
      <dc:creator>chayo</dc:creator>
      <dc:date>2013-07-01T21:20:48Z</dc:date>
    </item>
    <item>
      <title>Re: array to look up value from the previous record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-to-look-up-value-from-the-previous-record/m-p/123969#M25403</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If your data comes as is, lag() or dif() will be sufficient:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input ID $ Month $ Score;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;16 Jan12 112&lt;/P&gt;&lt;P&gt;16 Feb12 110&lt;/P&gt;&lt;P&gt;16 March12 100&lt;/P&gt;&lt;P&gt;16 April12 114&lt;/P&gt;&lt;P&gt;35 Jan12 120&lt;/P&gt;&lt;P&gt;35 Feb12 115&lt;/P&gt;&lt;P&gt;35 March 106&lt;/P&gt;&lt;P&gt;35 April 100&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; by id notsorted;&lt;/P&gt;&lt;P&gt;d=dif(score);&lt;/P&gt;&lt;P&gt;&amp;nbsp; if not first.id and d&amp;gt;0;&lt;/P&gt;&lt;P&gt;keep id;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 01 Jul 2013 22:12:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-to-look-up-value-from-the-previous-record/m-p/123969#M25403</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-07-01T22:12:03Z</dc:date>
    </item>
    <item>
      <title>Re: array to look up value from the previous record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-to-look-up-value-from-the-previous-record/m-p/123970#M25404</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;data have;
input ID $ Month $ Score;
cards;
16 Jan12 112
16 Feb12 110
16 March12 100
16 April12 114
35 Jan12 120
35 Feb12 115
35 March 106
35 April 100
;
run;
data want;
 set have;
 if id eq lag(id) and dif(score) gt 0;
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Jul 2013 01:17:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-to-look-up-value-from-the-previous-record/m-p/123970#M25404</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2013-07-02T01:17:30Z</dc:date>
    </item>
    <item>
      <title>Re: array to look up value from the previous record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/array-to-look-up-value-from-the-previous-record/m-p/123971#M25405</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;thank you Hai and ksharp for the help. it worked great! &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Jul 2013 14:07:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/array-to-look-up-value-from-the-previous-record/m-p/123971#M25405</guid>
      <dc:creator>chayo</dc:creator>
      <dc:date>2013-07-02T14:07:08Z</dc:date>
    </item>
  </channel>
</rss>

