<?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: Using arrays to see if consecutive elements are the same in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-arrays-to-see-if-consecutive-elements-are-the-same/m-p/476157#M122497</link>
    <description>&lt;P&gt;Thank you Reeza!&lt;/P&gt;</description>
    <pubDate>Fri, 06 Jul 2018 21:17:25 GMT</pubDate>
    <dc:creator>malmario</dc:creator>
    <dc:date>2018-07-06T21:17:25Z</dc:date>
    <item>
      <title>Using arrays to see if consecutive elements are the same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-arrays-to-see-if-consecutive-elements-are-the-same/m-p/476138#M122492</link>
      <description>&lt;P&gt;I have a data set with the variables VentUnit1-VentUnit151,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been attempting to use arrays to flag observations in which VentUnit(i) in ('8N-ICU, '8S-NSICU') and VentUnit(i+1) in&amp;nbsp;&lt;SPAN&gt;('8N-ICU, '8S-NSICU') such as Line#4 in the screenshot.&amp;nbsp; I'm having trouble trying to code this with do loops and have a feeling I'm taking the wrong approach.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="VentUnitScreenShot.JPG" style="width: 510px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21625iB9346053E46CA6AB/image-size/large?v=v2&amp;amp;px=999" role="button" title="VentUnitScreenShot.JPG" alt="VentUnitScreenShot.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any thoughts?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jul 2018 20:10:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-arrays-to-see-if-consecutive-elements-are-the-same/m-p/476138#M122492</guid>
      <dc:creator>malmario</dc:creator>
      <dc:date>2018-07-06T20:10:47Z</dc:date>
    </item>
    <item>
      <title>Re: Using arrays to see if consecutive elements are the same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-arrays-to-see-if-consecutive-elements-are-the-same/m-p/476140#M122493</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;I'm having trouble trying to code this with do loops and have a feeling I'm taking the wrong approach.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Can you show us the code you're using?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67956"&gt;@malmario&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a data set with the variables VentUnit1-VentUnit151,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have been attempting to use arrays to flag observations in which VentUnit(i) in ('8N-ICU, '8S-NSICU') and VentUnit(i+1) in&amp;nbsp;&lt;SPAN&gt;('8N-ICU, '8S-NSICU') such as Line#4 in the screenshot.&amp;nbsp; I'm having trouble trying to code this with do loops and have a feeling I'm taking the wrong approach.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="VentUnitScreenShot.JPG" style="width: 510px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21625iB9346053E46CA6AB/image-size/large?v=v2&amp;amp;px=999" role="button" title="VentUnitScreenShot.JPG" alt="VentUnitScreenShot.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Any thoughts?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jul 2018 20:12:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-arrays-to-see-if-consecutive-elements-are-the-same/m-p/476140#M122493</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-06T20:12:07Z</dc:date>
    </item>
    <item>
      <title>Re: Using arrays to see if consecutive elements are the same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-arrays-to-see-if-consecutive-elements-are-the-same/m-p/476145#M122494</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data lines5;
	set lines4;

	array Unit (*) VentUnit1-VentUnit151;

		do i=1 to i=151;
			if Unit(i) in ('8N-ICU','8S-NSICU') and Unit(i+1) in ('8N-ICU','8S-NSICU') then check+1;
		end;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 06 Jul 2018 20:18:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-arrays-to-see-if-consecutive-elements-are-the-same/m-p/476145#M122494</guid>
      <dc:creator>malmario</dc:creator>
      <dc:date>2018-07-06T20:18:43Z</dc:date>
    </item>
    <item>
      <title>Re: Using arrays to see if consecutive elements are the same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-arrays-to-see-if-consecutive-elements-are-the-same/m-p/476147#M122496</link>
      <description>&lt;LI-CODE lang="sas"&gt;do i&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; to i&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;151&lt;/SPAN&gt;&lt;/LI-CODE&gt;
&lt;P&gt;This is likely wrong and should&amp;nbsp;&amp;nbsp;be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i=1 to dim(unit)-1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Because you're checking i+1 you can only go up to one less than the dimension and you can use the DIM() function to get the number of elements.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may also want to set CHECK to 0 at the beginning of the loop but otherwise that seems correct.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data lines5;
	set lines4;

	array Unit (*) VentUnit1-VentUnit151;

check=0;

		do i=1 to dim(unit)-1;
			if Unit(i) in ('8N-ICU','8S-NSICU') and Unit(i+1) in ('8N-ICU','8S-NSICU') then check+1;
		end;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jul 2018 20:24:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-arrays-to-see-if-consecutive-elements-are-the-same/m-p/476147#M122496</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-06T20:24:36Z</dc:date>
    </item>
    <item>
      <title>Re: Using arrays to see if consecutive elements are the same</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-arrays-to-see-if-consecutive-elements-are-the-same/m-p/476157#M122497</link>
      <description>&lt;P&gt;Thank you Reeza!&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jul 2018 21:17:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-arrays-to-see-if-consecutive-elements-are-the-same/m-p/476157#M122497</guid>
      <dc:creator>malmario</dc:creator>
      <dc:date>2018-07-06T21:17:25Z</dc:date>
    </item>
  </channel>
</rss>

