<?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: Arrays - comparing consecutive values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Arrays-comparing-consecutive-values/m-p/651201#M195354</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/290100"&gt;@zishaq&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do I amend the do loop so we accept instances where the values are within +-5 when comparing? In other words it doesn't have to be an exact match but has to be close...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So you mean instead of testing&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x = y&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You want to test&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;-5 &amp;lt;= (x-y) &amp;lt;= 5&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 27 May 2020 19:58:04 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-05-27T19:58:04Z</dc:date>
    <item>
      <title>Arrays - comparing consecutive values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays-comparing-consecutive-values/m-p/651173#M195339</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset below and want to compute the columns shown in red:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Individual &amp;nbsp;&amp;nbsp; Month_01 &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;Month_02&lt;/STRONG&gt; &amp;nbsp;&amp;nbsp; &lt;STRONG&gt;Month_03&lt;/STRONG&gt; &amp;nbsp;&amp;nbsp; &lt;STRONG&gt;Month_04&lt;/STRONG&gt; &amp;nbsp; &amp;nbsp;&lt;STRONG&gt; &lt;FONT color="#ff0000"&gt;INSTANCES_EQUAL&lt;/FONT&gt; &amp;nbsp; &amp;nbsp; &lt;FONT color="#ff0000"&gt;NUMBER_POSITIVE &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; RATIO &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; TYPE&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;X &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; . &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 100 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 100 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; . &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;FONT color="#ff0000"&gt;1&lt;FONT&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/FONT&gt; 2&lt;FONT&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; FIXED&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Y &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 300&lt;SPAN style="background-color: #ffffff; box-sizing: border-box; color: #333333; cursor: text; display: inline; float: none; font-family: inherit; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 1.7142; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 300 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 300 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 300 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#005500"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;FONT color="#ff0000"&gt;3&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT color="#ff0000"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0.75 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; FIXED&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Z &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 450&lt;SPAN style="background-color: #ffffff; box-sizing: border-box; color: #333333; cursor: text; display: inline; float: none; font-family: inherit; font-size: 16px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 1.7142; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 500 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; 450 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 500 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;FONT color="#005500"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; &lt;FONT color="#ff0000"&gt;0&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT color="#ff0000"&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; VARIABLE&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;INSTANCES_EQUAL&lt;/STRONG&gt; compares the exact value in each consecutive month in pairs (i.e. month_01 against month_02, month_02 against month_03 etc). I also want to allow a leeway of +-5 either way. So taking individual X, if they had a value between 95 and 105 in Month_03 then this is fine and we can say that this is an instance. Also, it's important that it only compares values that are non-missing (i.e. greater than zero).&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;NUMBER_POSITIVE&lt;/STRONG&gt; provides the number of positive values (i.e. greater than zero) for each row.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RATIO&amp;nbsp;&lt;/STRONG&gt;is a calculation where INSTANCES_EQUAL / NUMBER_POSITIVE.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;TYPE&amp;nbsp;&lt;/STRONG&gt;is a character variable which takes ratio value and categorises this as "FIXED" if &amp;gt;=0.5 and "VARIABLE" if &amp;lt; 0.5&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I feel like there is a shortcut way of doing this in one program node using ARRAYS but not sure where to start?!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would be grateful for any advice.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 27 May 2020 18:32:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays-comparing-consecutive-values/m-p/651173#M195339</guid>
      <dc:creator>zishaq</dc:creator>
      <dc:date>2020-05-27T18:32:05Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays - comparing consecutive values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays-comparing-consecutive-values/m-p/651176#M195341</link>
      <description>&lt;P&gt;Try this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Individual $ Month_01-Month_04;
datalines;
X .   100 100 .
Y 300 300 300 300
Z 450 500 450 500
;

data want(drop=i);
   set have;
   array m{*} Month_01-Month_04;
   instances_equal = 0;
   do i=1 to dim(m)-1;
      if m[i+1] = m[i] then instances_equal+1;
   end;
   number_positive = n(of m[*]);
   ratio = instances_equal / number_positive;
   type = ifc(ratio ge .5, "FIXED", "VARIABLE");
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 May 2020 18:53:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays-comparing-consecutive-values/m-p/651176#M195341</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-05-27T18:53:26Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays - comparing consecutive values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays-comparing-consecutive-values/m-p/651184#M195346</link>
      <description>&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I amend the do loop so we accept instances where the values are within +-5 when comparing? In other words it doesn't have to be an exact match but has to be close...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 May 2020 19:19:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays-comparing-consecutive-values/m-p/651184#M195346</guid>
      <dc:creator>zishaq</dc:creator>
      <dc:date>2020-05-27T19:19:51Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays - comparing consecutive values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays-comparing-consecutive-values/m-p/651199#M195353</link>
      <description>&lt;P&gt;How about&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Individual $ Month_01-Month_04;
datalines;
X .   100 100 .
Y 300 300 300 300
Z 450 500 450 500
;

data want(drop=i);
   set have;
   array m{*} Month_01-Month_04;
   instances_equal = 0;
   do i=1 to dim(m)-1;
      if . &amp;lt; abs(m[i+1]-m[i]) &amp;lt;= 5 then instances_equal+1;
   end;
   number_positive = n(of m[*]);
   ratio = instances_equal / number_positive;
   type = ifc(ratio ge .5, "FIXED", "VARIABLE");
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 May 2020 19:54:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays-comparing-consecutive-values/m-p/651199#M195353</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-05-27T19:54:42Z</dc:date>
    </item>
    <item>
      <title>Re: Arrays - comparing consecutive values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arrays-comparing-consecutive-values/m-p/651201#M195354</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/290100"&gt;@zishaq&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do I amend the do loop so we accept instances where the values are within +-5 when comparing? In other words it doesn't have to be an exact match but has to be close...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So you mean instead of testing&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x = y&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You want to test&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;-5 &amp;lt;= (x-y) &amp;lt;= 5&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 May 2020 19:58:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arrays-comparing-consecutive-values/m-p/651201#M195354</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-05-27T19:58:04Z</dc:date>
    </item>
  </channel>
</rss>

