<?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: Odd glitch with the CHOOSE function in IML in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Odd-glitch-with-the-CHOOSE-function-in-IML/m-p/28164#M132</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I wouldn't say it's a "glitch." As I point out in my blog post&lt;/P&gt;&lt;P&gt;&lt;A href="http://blogs.sas.com/content/iml/2011/08/15/complex-assignment-statements-choose-wisely/"&gt;http://blogs.sas.com/content/iml/2011/08/15/complex-assignment-statements-choose-wisely/&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;you shouldn't think of CHOOSE as equivalent to the IF-THEN/ELSE statement, although they are similar. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The general formulation of the CHOOSE statement is to have three vectors as arguments. As I say in my blog:&lt;BR /&gt;"The CHOOSE function examines each element of the first argument. If an element is nonzero, it returns the corresponding element of the second argument. If an element is zero, it returns the corresponding element of the third argument."&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the general case, therefore, the dimensions of the three arguments must be the same. That's why the CHOOSE function is complaining that the second and third arguments are different dimensions. However, in your example the first argument is a scalar. Although CHOOSE &lt;EM&gt;could&lt;/EM&gt; handle this case differently than the general case, that's not how it works, because special-casing certain behaviors can lead to other problems.&amp;nbsp; For example, the statement C = choose(i=2, ., A) is valid syntax. In your scheme, it's not clear whether&amp;nbsp; C should be a vector of missing values, or just a scalar missing value.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 12 Oct 2011 12:50:53 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2011-10-12T12:50:53Z</dc:date>
    <item>
      <title>Odd glitch with the CHOOSE function in IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Odd-glitch-with-the-CHOOSE-function-in-IML/m-p/28163#M131</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-family: 'comic sans ms', fantasy; padding-right: 15px; padding-left: 15px; vertical-align: baseline; background-color: #f6f7f7; line-height: 18px; text-align: -webkit-auto;"&gt;Here's a very odd glitch with CHOOSE that I discovered recently. Try this:&lt;/P&gt;&lt;P style="font-family: 'comic sans ms', fantasy; padding-right: 15px; padding-left: 15px; vertical-align: baseline; background-color: #f6f7f7; line-height: 18px; text-align: -webkit-auto;"&gt;a = J(1,6,0);&lt;BR /&gt;b = J(1,6,1);&lt;BR /&gt;i = 2;&lt;BR /&gt;a = choose(i=1,b,a//b);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'comic sans ms', fantasy; padding-right: 15px; padding-left: 15px; vertical-align: baseline; background-color: #f6f7f7; line-height: 18px; text-align: -webkit-auto;"&gt;In words, if i = 1, I want 'a' to become 'b', otherwise, I want 'b' to be appended to 'a'. Doesn't work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'comic sans ms', fantasy; padding-right: 15px; padding-left: 15px; vertical-align: baseline; background-color: #f6f7f7; line-height: 18px; text-align: -webkit-auto;"&gt;Now, replace the CHOOSE statement in the code above with the following equivalent if/then/else statement:&lt;BR /&gt;if i=1 then a = b; else a = a//b;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'comic sans ms', fantasy; padding-right: 15px; padding-left: 15px; vertical-align: baseline; background-color: #f6f7f7; line-height: 18px; text-align: -webkit-auto;"&gt;It will work. Why doesn't it work when using the CHOOSE function ? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Oct 2011 11:09:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Odd-glitch-with-the-CHOOSE-function-in-IML/m-p/28163#M131</guid>
      <dc:creator>Ange</dc:creator>
      <dc:date>2011-10-12T11:09:23Z</dc:date>
    </item>
    <item>
      <title>Re: Odd glitch with the CHOOSE function in IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Odd-glitch-with-the-CHOOSE-function-in-IML/m-p/28164#M132</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I wouldn't say it's a "glitch." As I point out in my blog post&lt;/P&gt;&lt;P&gt;&lt;A href="http://blogs.sas.com/content/iml/2011/08/15/complex-assignment-statements-choose-wisely/"&gt;http://blogs.sas.com/content/iml/2011/08/15/complex-assignment-statements-choose-wisely/&lt;/A&gt;,&lt;/P&gt;&lt;P&gt;you shouldn't think of CHOOSE as equivalent to the IF-THEN/ELSE statement, although they are similar. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The general formulation of the CHOOSE statement is to have three vectors as arguments. As I say in my blog:&lt;BR /&gt;"The CHOOSE function examines each element of the first argument. If an element is nonzero, it returns the corresponding element of the second argument. If an element is zero, it returns the corresponding element of the third argument."&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the general case, therefore, the dimensions of the three arguments must be the same. That's why the CHOOSE function is complaining that the second and third arguments are different dimensions. However, in your example the first argument is a scalar. Although CHOOSE &lt;EM&gt;could&lt;/EM&gt; handle this case differently than the general case, that's not how it works, because special-casing certain behaviors can lead to other problems.&amp;nbsp; For example, the statement C = choose(i=2, ., A) is valid syntax. In your scheme, it's not clear whether&amp;nbsp; C should be a vector of missing values, or just a scalar missing value.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Oct 2011 12:50:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Odd-glitch-with-the-CHOOSE-function-in-IML/m-p/28164#M132</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2011-10-12T12:50:53Z</dc:date>
    </item>
  </channel>
</rss>

