<?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 do until() issue in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/do-until-issue/m-p/50512#M10547</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Most likely cause is that in the second step the first reference to VAR1 is in the UNTIL() clause. In the first one the first reference is the SET statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am not sure why SAS assumes var1 is numeric if the first reference to it is in a COMPRESS() function.&amp;nbsp; You would think that would imply a character variable.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 30 Mar 2012 18:34:24 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2012-03-30T18:34:24Z</dc:date>
    <item>
      <title>do until() issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-until-issue/m-p/50510#M10545</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A short while ago, some one asked how to reset the count every time there is a 'N'. So I was thinking if I can reset it every time if there is a CAPITAL character, it turned out not hard to do, as I am going to show you below. However, what I thought would-be equavalent expression seems not equavalent, one working, one not:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Working solution:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input var1$;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;a&lt;/P&gt;&lt;P&gt;b&lt;/P&gt;&lt;P&gt;c&lt;/P&gt;&lt;P&gt;N&lt;/P&gt;&lt;P&gt;q&lt;/P&gt;&lt;P&gt;r&lt;/P&gt;&lt;P&gt;a&lt;/P&gt;&lt;P&gt;S&lt;/P&gt;&lt;P&gt;e&lt;/P&gt;&lt;P&gt;N&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want (drop=v);&lt;/P&gt;&lt;P&gt;do ct=1 by 1&amp;nbsp; until (v);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; v=missing(compress(var1,,'u'));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; output;&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;After I switch the contents of 'v' into until(), SAS tells me:&lt;/P&gt;&lt;P&gt;ERROR: Variable var1 has been defined as both character and numeric.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;do ct=1 by 1&amp;nbsp; until (missing(compress(var1,,'u')));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; output;&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;&lt;/P&gt;&lt;P&gt;Please shed some light on this one and educate me.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Mar 2012 17:53:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-until-issue/m-p/50510#M10545</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-03-30T17:53:25Z</dc:date>
    </item>
    <item>
      <title>do until() issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-until-issue/m-p/50511#M10546</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If it makes you feel any better, I don't have any idea why it would behave that way either.&amp;nbsp; My vote is that it is a bug!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Mar 2012 18:28:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-until-issue/m-p/50511#M10546</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-03-30T18:28:08Z</dc:date>
    </item>
    <item>
      <title>do until() issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-until-issue/m-p/50512#M10547</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Most likely cause is that in the second step the first reference to VAR1 is in the UNTIL() clause. In the first one the first reference is the SET statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am not sure why SAS assumes var1 is numeric if the first reference to it is in a COMPRESS() function.&amp;nbsp; You would think that would imply a character variable.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Mar 2012 18:34:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-until-issue/m-p/50512#M10547</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-03-30T18:34:24Z</dc:date>
    </item>
    <item>
      <title>do until() issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-until-issue/m-p/50513#M10548</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;LOL. Art, your answer does make me feel better, that is why it is helpful!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Mar 2012 18:35:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-until-issue/m-p/50513#M10548</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-03-30T18:35:36Z</dc:date>
    </item>
    <item>
      <title>Re: do until() issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-until-issue/m-p/50514#M10549</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tom, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I would usually agree with you without even blink. But today you have two more questions of mine:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Do until() will not be evaluated until the end of the loop, so why does it matter?&lt;/P&gt;&lt;P&gt;2. And please look below, var1 is character and the first encounter happens in until()?&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input var1$;&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;a&lt;/P&gt;&lt;P&gt;b&lt;/P&gt;&lt;P&gt;c&lt;/P&gt;&lt;P&gt;N&lt;/P&gt;&lt;P&gt;q&lt;/P&gt;&lt;P&gt;r&lt;/P&gt;&lt;P&gt;a&lt;/P&gt;&lt;P&gt;S&lt;/P&gt;&lt;P&gt;e&lt;/P&gt;&lt;P&gt;N&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;data want ;&lt;/P&gt;&lt;P&gt;do ct=1 by 1&amp;nbsp; until (var1='N');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; output;&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;proc print;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Mar 2012 18:44:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-until-issue/m-p/50514#M10549</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-03-30T18:44:52Z</dc:date>
    </item>
    <item>
      <title>Re: do until() issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-until-issue/m-p/50515#M10550</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My view is that SAS is actually compiling the data step code.&amp;nbsp; So the first time the COMPILER sees the variable it makes a determination on what type and length to give.&amp;nbsp; Execution order does not matter. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Some times it is obvious.&amp;nbsp; A LENGTH or ATTRIB statement or a reference to an existing dataset in the SET statement.&lt;/P&gt;&lt;P&gt;Next level of easy are simple assignment or comparisons.&amp;nbsp; Your last example is easy for SAS.&amp;nbsp; It sees that you are testing if VAR1 is equal to a character string so VAR1 gets defined as character. The length of the comparison string is known so VAR1 is length 1.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If SAS can't figure it out it defaults to numeric.&lt;/P&gt;&lt;P&gt;Apparently SAS cannot tell that a variable referenced as the first argument to COMPRESS() function should be a string.&amp;nbsp; So it gets defined as a number which conflicts with the definition in the dataset referenced later in the SAS statement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Mar 2012 19:03:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-until-issue/m-p/50515#M10550</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-03-30T19:03:27Z</dc:date>
    </item>
    <item>
      <title>Re: do until() issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/do-until-issue/m-p/50516#M10551</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tom is correct, but I still think it is a bug!&amp;nbsp; You can get around it by pre-informing SAS that it really is a character variable.&amp;nbsp; e.g.:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; length var1 $1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do ct=1 by 1&amp;nbsp; until (missing(compress(var1,,'u')));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 30 Mar 2012 19:04:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/do-until-issue/m-p/50516#M10551</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2012-03-30T19:04:33Z</dc:date>
    </item>
  </channel>
</rss>

