<?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: Specifying array length in do statement in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Specifying-array-length-in-do-statement/m-p/650880#M78743</link>
    <description>Thank you! This did the trick. Any idea why when I specified this way (z=1 to z=11) earlier in my code I did not encounter any problems? Are there instances when one should specify in this way?</description>
    <pubDate>Tue, 26 May 2020 18:46:17 GMT</pubDate>
    <dc:creator>raivester</dc:creator>
    <dc:date>2020-05-26T18:46:17Z</dc:date>
    <item>
      <title>Specifying array length in do statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Specifying-array-length-in-do-statement/m-p/650873#M78741</link>
      <description>&lt;P&gt;I am fairly new to SAS and am still learning nuances. The first snippet of code below runs; however, when I change the "do" line to "do z=1 to z=11;" the code no longer runs. I had done this in a previous section of my code and it worked fine, but not here. Can anyone explain why this is the case? I hope to figure this out because this seems to be the problem preventing me from running the second code snippet where I want to do one things for the first 11 elements and another thing for the additional 10 elements (Second code snippet shows what I ultimately hope to do).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Snippet 1:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;length var1 var2 var3 var4 var5 var6 var7 var8 var9 var10 var11 $3.;
 array varin raw1 raw2 raw3 raw4 raw5 raw6 raw7 raw8 raw9 raw10 raw11;
 array varout var1 var2 var3 var4 var5 var6 var7 var8 var9 var10 var11;

do z=1 to dim(varin);
  if varin[z] ~in(. 0) then do;
 	varout[z] = put(varin[z], 3.);
  end;
  else do;
 	varout[z] = "";
  end;
end;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is ultimately what I hope to be able to do:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Snippet 2:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;length var1 var2 var3 var4 var5 var6 var7 var8 var9 var10 var11 $3.;
length cnt1 cnt2 cnt3 cnt4 cnt5 cnt6 cnt7 cnt8 cnt9 cnt10 $2.;
 array varin raw1 raw2 raw3 raw4 raw5 raw6 raw7 raw8 raw9 raw10 raw11 ctraw1 ctraw2 ctraw3 ctraw4 ctraw5 ctraw6 ctraw7 ctraw8 ctraw9 ctraw10;
 array varout var1 var2 var3 var4 var5 var6 var7 var8 var9 var10 var11 cnt1 cnt2 cnt3 cnt4 cnt5 cnt6 cnt7 cnt8 cnt9 cnt10;

do z=1 to z=11;
  if varin[z] ~in(. 0) then do;
 	varout[z] = put(varin[z], 3.);
  end;
  else do;
 	varout[z] = "";
  end;
end;
do z=12 to z=21;
  if varin[z] ~=. then do;
 	varout[z] = put(varin[z], 2.);
  end;
  else do;
 	varout[z] = "";
  end;
end;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 May 2020 18:32:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Specifying-array-length-in-do-statement/m-p/650873#M78741</guid>
      <dc:creator>raivester</dc:creator>
      <dc:date>2020-05-26T18:32:52Z</dc:date>
    </item>
    <item>
      <title>Re: Specifying array length in do statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Specifying-array-length-in-do-statement/m-p/650876#M78742</link>
      <description>&lt;P&gt;The syntax is&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do z = 1 to 11;&lt;/P&gt;</description>
      <pubDate>Tue, 26 May 2020 18:38:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Specifying-array-length-in-do-statement/m-p/650876#M78742</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-05-26T18:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: Specifying array length in do statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Specifying-array-length-in-do-statement/m-p/650880#M78743</link>
      <description>Thank you! This did the trick. Any idea why when I specified this way (z=1 to z=11) earlier in my code I did not encounter any problems? Are there instances when one should specify in this way?</description>
      <pubDate>Tue, 26 May 2020 18:46:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Specifying-array-length-in-do-statement/m-p/650880#M78743</guid>
      <dc:creator>raivester</dc:creator>
      <dc:date>2020-05-26T18:46:17Z</dc:date>
    </item>
    <item>
      <title>Re: Specifying array length in do statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Specifying-array-length-in-do-statement/m-p/650883#M78745</link>
      <description>&lt;P&gt;Doesn't run is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the &amp;lt;&amp;gt; to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat&lt;/A&gt;... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the &amp;lt;&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your array only has 11 elements. So when you start with Z=11 then it will only process the 11th skipping 1 through 10, raw11 and assign, possibly, a value to var11.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your&lt;/P&gt;
&lt;PRE class="lia-code-sample  language-markup"&gt;&lt;CODE&gt;  else do;
 	varout[z] = "";
  end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Is not needed unless&amp;nbsp; varout[z] already has a value. If you do not assign a value the variable will have a missing value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Without specific values it is hard to be sure but with your put statement using two different formats you have a potential of creating values with a leading space. The Put with a value of 2 and format of 3. by default will create a value of "&amp;nbsp; 2". If you don't want leading spaces in that case you may want to use the option in the Put of -L to left justify the result. Put(var, 3. -L) for example.&lt;/P&gt;</description>
      <pubDate>Tue, 26 May 2020 18:51:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Specifying-array-length-in-do-statement/m-p/650883#M78745</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-26T18:51:04Z</dc:date>
    </item>
    <item>
      <title>Re: Specifying array length in do statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Specifying-array-length-in-do-statement/m-p/651421#M78756</link>
      <description>&lt;P&gt;A logical expression resolves to 1 for true and 0 for false&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So your loop code as&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DO Z = 1 to Z = 11;&lt;/PRE&gt;
&lt;P&gt;is compiled as&lt;/P&gt;
&lt;PRE&gt;DO Z = 1 to (Z=11);&lt;/PRE&gt;
&lt;P&gt;which logical expression evaluation is&lt;/P&gt;
&lt;PRE&gt;DO Z = 1 to 0;&lt;/PRE&gt;
&lt;P&gt;and will perform 0 iterations because to stop value is less than the start value (with a tacit &lt;CODE&gt;BY 1&lt;/CODE&gt;)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The termination value of a DO loop is computed&amp;nbsp;&lt;STRONG&gt;one&lt;/STRONG&gt; time as program flow reaches the DO statement.&amp;nbsp; The only way to get a 'single' step is if (Z=11) is true, which would resolve to 1, which can only happen if Z is 11 just prior to the DO loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would &lt;STRONG&gt;not likely&lt;/STRONG&gt; see this form &lt;EM&gt;top of loop is 0 or 1 per some logic expression.&amp;nbsp; &lt;/EM&gt;An obfuscatorial or job security coding mind-set might code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;do index = 1 to &amp;lt;logic-expression&amp;gt;;
  * statements;
end;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When this is more appropriate&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;if &amp;lt;logic-expression&amp;gt; then do;
  * statements;
end;&lt;/LI-CODE&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;
&lt;P&gt;You may on occasion see the &lt;EM&gt;top computed once&amp;nbsp;&lt;/EM&gt;feature of the DO LOOP in effect in a DOW loop over group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;DO _N_ = 1 by 1 until (last.ID);
  set have;
  by ID;
  * x = group level computation;
end;

DO _N_ = 1 to _N_;  /* top of this DO loop is _N_ value from prior DO loop */
  set have;
  output;  * computed x value now available to every row in group;
end;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 May 2020 15:28:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Specifying-array-length-in-do-statement/m-p/651421#M78756</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-05-28T15:28:46Z</dc:date>
    </item>
  </channel>
</rss>

