<?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: Do Loops in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Do-Loops/m-p/93018#M26466</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;CATX() will skip the missing values.&amp;nbsp; So catx('|','A',' ',9,.,'C') will be 'A|9|C' .&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 02 Jun 2013 21:46:37 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2013-06-02T21:46:37Z</dc:date>
    <item>
      <title>Do Loops</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-Loops/m-p/93011#M26459</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;Hi,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;The following example deletes the records whose missing values(numeric and char) are ge 10&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;in the following example why has the &lt;STRONG&gt;author&lt;/STRONG&gt; used the j=1to dim(nm)?? Cant it be written as i=1 to dim(nm) ?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;i dint understand this concept. Could anyone explain &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;Thanks&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;data complete;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;set maybeokay;&lt;/P&gt;&lt;P&gt;misscount = 0;&lt;/P&gt;&lt;P&gt;array ch(*) _character_ ;&lt;/P&gt;&lt;P&gt;array nm(*) _numeric_ ;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;do i = 1 to dim(ch);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;if ch(i) = ' ' then misscount + 1;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;do j = 1 to dim(nm);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;if nm(j) = . then misscount + 1;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;drop i j ;&lt;/P&gt;&lt;P&gt;if misscount ge 10 then delete;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/sugi26/p052-26.pdf" style="font-size: 10pt; line-height: 1.5em;" title="http://www2.sas.com/proceedings/sugi26/p052-26.pdf"&gt;http://www2.sas.com/proceedings/sugi26/p052-26.pdf&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Jun 2013 19:41:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-Loops/m-p/93011#M26459</guid>
      <dc:creator>robertrao</dc:creator>
      <dc:date>2013-06-02T19:41:38Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loops</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-Loops/m-p/93012#M26460</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I assume it is because that is what made sense at the time.&lt;/P&gt;&lt;P&gt;You are right that they could have re-used I as the loop variable for the second loop. &lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;But if the loops were nested that would cause trouble. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;In the past I would normally use DO OVER construct for situations like this where the index variable is meaningless and avoid having to worry about dropping the variable.&amp;nbsp; (Note that it doesn't solve the issue of nested do loops as DO OVER use the automatic _I_ variable for indexing.)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that setting MISSCOUNT to zero is critical in this program because of the use of the sum statement (&lt;EM&gt;var + value;&lt;/EM&gt;)&amp;nbsp; since it means MISSCOUNT is retained.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Now that SAS has added so many new functions over the years I would use the NMISS() function to count the _NUMERIC_ missings.&amp;nbsp; You could probably do something with COUNTW() and CATX() to count missing characters, but you would need to find an unused character to serve as the delimiter.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;misscount=0;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;array ch _character_;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;misscount=nmiss(of _numeric_) + dim(ch) - countw(catx('00'x,of ch(*)),'00'x);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that setting MISSCOUNT to zero is critical here also because it will be included in the _NUMERIC_ variable list.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Both programs will have trouble when there are no character variables in the input datastep since you cannot define an array with no elements. You could solve that by creating a dummy character variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;misscount=0;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;retain _ch 'A';&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;drop _ch;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;STRONG&gt;array ch _character_;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;misscount=nmiss(of _numeric_) + dim(ch) - countw(catx('00'x,of ch(*)),'00'x) ;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Jun 2013 20:19:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-Loops/m-p/93012#M26460</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-06-02T20:19:29Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loops</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-Loops/m-p/93013#M26461</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, the author could have used i instead of j for the second loop. The result would have been the same. The difference in efficiency would have been insignificant. The name of the do loop variable matters only if you want to use it after the end of the loop. For example :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;do i = 1 to dim(ch);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ch(i) = ' ' then leave;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;do j = 1 to dim(nm);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ch(j) = ' ' then leave;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;end;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;hasMissing = i &amp;lt; dim(ch) or j &amp;lt; dim(nm);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Jun 2013 20:27:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-Loops/m-p/93013#M26461</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2013-06-02T20:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loops</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-Loops/m-p/93014#M26462</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Thanks for the detailed explanation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;could you explain whats happening here??????its a lil bit confusing as to why the '00'x was used???????/&lt;/P&gt;&lt;P&gt;also why the substraction logic is done????/&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;misscount=nmiss(of _numeric_) + dim(ch) - countw(catx('00'x,of ch(*)),'00'x) ;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Thanks&lt;BR /&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Jun 2013 20:59:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-Loops/m-p/93014#M26462</guid>
      <dc:creator>robertrao</dc:creator>
      <dc:date>2013-06-02T20:59:30Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loops</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-Loops/m-p/93015#M26463</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How about :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;misscount = 0;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;misscount = cmiss(of _all_);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;or, if you don't need the number of missing values:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 10pt;"&gt;data complete;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;set maybeokay;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;if cmiss( of _all_)&amp;nbsp; &amp;lt;= 10;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Jun 2013 21:16:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-Loops/m-p/93015#M26463</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2013-06-02T21:16:45Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loops</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-Loops/m-p/93016#M26464</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;COUNTW() counts words by using a delimiter. It is counting non-missing hence the need to subtract from the number of items in the array. So I use binary zero ('00'x) as the delimiter as it is extremely unlikely to be an actual character in your data.&amp;nbsp; But see response below from &lt;A __default_attr="2746" __jive_macro_name="user" class="jive_macro jive_macro_user" href="https://communities.sas.com/"&gt;&lt;/A&gt; that uses another function I didn't find.&amp;nbsp; CMISS() will work for both numeric and character variables. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;misscount=cmiss(of _all_);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It would help if SAS was more consistent in its documentation as I looked for a See Also section in the documentation for NMISS() and missed that CMISS() was instead only included in a Comparisons section instead.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE cellpadding="0" cellspacing="0" style="font-family: arial, 'Arial Unicode MS', geneva, 'Lucida Grande', sans-serif; color: #000000; background-color: #ffffff;" width="100%"&gt;&lt;TBODY style="font-family: inherit;"&gt;&lt;TR style="font-family: inherit;" valign="top"&gt;&lt;TD class="title2" style="font-weight: bold; font-size: 16px; margin-top: 1.4em;"&gt;&lt;A name="a003154857"&gt;&lt;/A&gt;Comparisons&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P style="margin: 1.4em 0px 0px; font-family: arial, 'Arial Unicode MS', geneva, 'Lucida Grande', sans-serif; color: #000000; background-color: #ffffff;"&gt;The NMISS function returns the number of missing values, whereas the N function returns the number of nonmissing values. NMISS requires numeric values, whereas CMISS works with both numeric and character values. NMISS works with multiple numeric values, whereas MISSING works with only one value that can be either numeric or character.&lt;/P&gt;&lt;TABLE cellpadding="0" cellspacing="0" style="font-family: arial, 'Arial Unicode MS', geneva, 'Lucida Grande', sans-serif; color: #000000; background-color: #ffffff;" width="100%"&gt;&lt;TBODY style="font-family: inherit;"&gt;&lt;TR style="font-family: inherit;" valign="bottom"&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Jun 2013 21:25:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-Loops/m-p/93016#M26464</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-06-02T21:25:55Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loops</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-Loops/m-p/93017#M26465</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So when you concatenate all the values under all the char variables with &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;STRONG&gt;'00'x&lt;/STRONG&gt;&lt;/SPAN&gt; wont the dim(ch) be equalant to the countw???&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is it like when a char value is missing &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;STRONG&gt;'00'x&lt;/STRONG&gt;&lt;/SPAN&gt; concatenates with &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;STRONG&gt;'00'x&lt;/STRONG&gt;&lt;/SPAN&gt;. And since there is no word between these two countw does not have a value now&lt;/P&gt;&lt;P&gt;only when there is &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;STRONG&gt;'00'x&lt;/STRONG&gt;&lt;/SPAN&gt;word&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;&lt;STRONG&gt;'00'x&lt;/STRONG&gt;&lt;/SPAN&gt; countw has a value to count???&lt;/P&gt;&lt;P&gt;Does it work like that??/&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also what the little x is doing beside the Zeros and why is it outside the braces????????&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Jun 2013 21:40:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-Loops/m-p/93017#M26465</guid>
      <dc:creator>robertrao</dc:creator>
      <dc:date>2013-06-02T21:40:50Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loops</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-Loops/m-p/93018#M26466</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;CATX() will skip the missing values.&amp;nbsp; So catx('|','A',' ',9,.,'C') will be 'A|9|C' .&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Jun 2013 21:46:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-Loops/m-p/93018#M26466</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-06-02T21:46:37Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loops</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-Loops/m-p/93019#M26467</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Finally why the little x in &lt;STRONG style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif;"&gt;'00'x is outside of the inverted comas?????&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Jun 2013 22:07:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-Loops/m-p/93019#M26467</guid>
      <dc:creator>robertrao</dc:creator>
      <dc:date>2013-06-02T22:07:16Z</dc:date>
    </item>
    <item>
      <title>Re: Do Loops</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Do-Loops/m-p/93020#M26468</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is how to represent a literal value using hexadecimal digits.&amp;nbsp; For example a space is represented by '20'x, tab by '09'x.&lt;/P&gt;&lt;P&gt;There are many other literals such date ('01JAN1960'd), time ('09:30't), datetime ('01JAN1960:09:30'dt).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000780334.htm" title="SAS(R) 9.2 Language Reference: Concepts, Second Edition"&gt;SAS Constants in Expressions&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 02 Jun 2013 22:22:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Do-Loops/m-p/93020#M26468</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-06-02T22:22:43Z</dc:date>
    </item>
  </channel>
</rss>

