<?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 arrays and nested loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/arrays-and-nested-loop/m-p/45155#M9301</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Thank you Tom. This really helped a lot.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;God Bless you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 10 Nov 2011 15:15:57 GMT</pubDate>
    <dc:creator>Swordfish</dc:creator>
    <dc:date>2011-11-10T15:15:57Z</dc:date>
    <item>
      <title>arrays and nested loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-and-nested-loop/m-p/45153#M9299</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 have 400 or more variables in the data set. For the illustration purpose I am limiting my data code to only 11 variables.&lt;/P&gt;&lt;P&gt;The issue is I want to create a variable “DF” based on the next two months balance. If the Balance/amount drops below 9 in any of the next two months the variable “ DF” gets “Y” else “N”.&lt;/P&gt;&lt;P&gt;I provide below the data I have and the data I want and the code that generates error.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sas data creation:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data months;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input m1 m2 m3 m4 m5 m6 m7 m8 m9 m10 m11;&lt;/P&gt;&lt;P&gt;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;&amp;nbsp; 20&amp;nbsp; 20&amp;nbsp;&amp;nbsp;&amp;nbsp; 50&amp;nbsp;&amp;nbsp;&amp;nbsp; 50&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 30&amp;nbsp;&amp;nbsp;&amp;nbsp; 5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 100&amp;nbsp;&amp;nbsp; 100&amp;nbsp;&amp;nbsp; 40&amp;nbsp;&amp;nbsp;&amp;nbsp; 40&lt;/P&gt;&lt;P&gt;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data I_wana_hav;&lt;/P&gt;&lt;P&gt;Input DF1 $ m1 DF2 $ m2 DF3 $ m3 DF4 $ m4 DF5 $ m5 DF6 $ m6 DF7 $ m7 DF8 $ m8 DF9 $ m9 DF10 $ m10 DF11 $ m11;&lt;/P&gt;&lt;P&gt;Datalines;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;N 20 N 20 N 50 Y&amp;nbsp; 50 Y 2 Y 30 Y 5 N 100 N 100 N 40 N&amp;nbsp; 40&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run; &lt;/P&gt;&lt;P&gt;/*code generates error*/Data test1;&lt;/P&gt;&lt;P&gt;set months;&lt;/P&gt;&lt;P&gt;array Am{*} m1-m11;&lt;/P&gt;&lt;P&gt;array ADF{*} $ DF1-DF11;&lt;/P&gt;&lt;P&gt;do j=1 to dim(AM);&lt;/P&gt;&lt;P&gt;do i=1 to 2;&lt;/P&gt;&lt;P&gt;if Am(j+i)&amp;lt;9 then ADF{j}="y";&lt;/P&gt;&lt;P&gt;else ADF{j}="N";&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help would be highly appreciated.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Nov 2011 14:42:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-and-nested-loop/m-p/45153#M9299</guid>
      <dc:creator>Swordfish</dc:creator>
      <dc:date>2011-11-10T14:42:53Z</dc:date>
    </item>
    <item>
      <title>Re: arrays and nested loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-and-nested-loop/m-p/45154#M9300</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The bounds for your inner loop should be J+1 and DIM(AM).&amp;nbsp; (or you could make the upper bound for your outer loop DIM(ADF)-2 )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code"&gt;&lt;P&gt;do j=1 to dim(ADF);&lt;/P&gt;&lt;P&gt;&amp;nbsp; ADF(j)= 'N';&lt;/P&gt;&lt;P&gt;&amp;nbsp; do i=j+1 to min(J+2,dim(AM));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if AM(i)&amp;lt;9 then ADF(j)="Y";&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Nov 2011 14:58:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-and-nested-loop/m-p/45154#M9300</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2011-11-10T14:58:14Z</dc:date>
    </item>
    <item>
      <title>arrays and nested loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-and-nested-loop/m-p/45155#M9301</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Thank you Tom. This really helped a lot.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;God Bless you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Nov 2011 15:15:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-and-nested-loop/m-p/45155#M9301</guid>
      <dc:creator>Swordfish</dc:creator>
      <dc:date>2011-11-10T15:15:57Z</dc:date>
    </item>
    <item>
      <title>Re: arrays and nested loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-and-nested-loop/m-p/45156#M9302</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi ... I think that the two loops might make this more complicated than necessary.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;data test1;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;set months;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;array m(11);&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;array df(11) $1 (11*'N');&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;do _n_ = 1 to 9;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;&amp;nbsp; df(_n_) = ifc(m(_n_+1) lt 9 or m(_n_+2) lt 9 , 'Y', 'N');&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;end;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you could use the asterisks and dim function in the above, but unless you do something previous to the data step to figure out how many&lt;/P&gt;&lt;P&gt;variables you are checking, you'll have to hard code the dimension of DF ... so why bother with the asterisks and dim function in your code ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff;"&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;array Am{*} m1-m11;&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff;"&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;array ADF{*} $ DF1-DF11;&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff;"&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;do j=1 to dim(AM);&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Nov 2011 16:42:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-and-nested-loop/m-p/45156#M9302</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2011-11-10T16:42:51Z</dc:date>
    </item>
    <item>
      <title>Re: arrays and nested loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-and-nested-loop/m-p/45157#M9303</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;&lt;P&gt;MikeZdeb wrote:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;you could use the asterisks and dim function in the above, but unless you do something previous to the data step to figure out how many&lt;/P&gt;&lt;P&gt;variables you are checking, you'll have to hard code the dimension of DF ... so why bother with the asterisks and dim function in your code ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff;"&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;array Am{*} m1-m11;&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff;"&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;array ADF{*} $ DF1-DF11;&lt;/STRONG&gt;&lt;/P&gt;&lt;P style="background-color: #ffffff;"&gt;&lt;STRONG style="font-family: 'courier new', courier;"&gt;do j=1 to dim(AM);&lt;/STRONG&gt;&lt;/P&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;Use of the DIM() makes it easier to keep the code working if you change the size of the array. For example suppose some requests a similar logic based on biweekly periods. Once the variables are assigned/created you don't have to remember to adjust the boundary on the loop. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you get to multiple nested loops you can really appreciate that feature.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Nov 2011 20:43:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-and-nested-loop/m-p/45157#M9303</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2011-11-10T20:43:13Z</dc:date>
    </item>
    <item>
      <title>Re: arrays and nested loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/arrays-and-nested-loop/m-p/45158#M9304</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi ... in this instance, you are talking about one line of code that follows several&amp;nbsp; lines that already require editiing as the array size changes.&amp;nbsp; If one wants to fix this example, you are better off with a macro variable that adjusts both arrays and the loop.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Nov 2011 21:15:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/arrays-and-nested-loop/m-p/45158#M9304</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2011-11-10T21:15:48Z</dc:date>
    </item>
  </channel>
</rss>

