<?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: Choose function vs. if-then do in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Choose-function-vs-if-then-do/m-p/173979#M1715</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, you can put a CHOOSE function inside another. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are only doing this choice a few times, then it doesn't matter which conditional statements you use, and I'd choose the IF-THEN because it is easier to read. If this is going to be inside a big loop, then you might want to compare the performance by timing the computations. See &lt;A href="http://blogs.sas.com/content/iml/2012/12/05/remove-or-keep-which-is-faster/" title="http://blogs.sas.com/content/iml/2012/12/05/remove-or-keep-which-is-faster/"&gt; Remove or keep: Which is faster? - The DO Loop&lt;/A&gt; or Chapter 15 of &lt;EM&gt;Statistical Programming with SAS/IML Software.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regarding your nested CHOOSE construction, you are missing a final 'else'.&amp;nbsp; What happens if Line^='PP'? It should read:&lt;/P&gt;&lt;P&gt;Guar = choose(Line = 'PP', choose(...), SOMEVALUE );&lt;/P&gt;&lt;P&gt;A trick that I like to use is to precompute the nested values so that the nested CHOOSE functions aren't so hard to read. Something like this might be helpful if you 'choose' to use nested CHOOSE functions:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* possible results */&lt;BR /&gt;R1 = round(App # Level * .65, .1);&lt;BR /&gt;R2 = round(App # Level * .70, .1);&lt;BR /&gt;R3 = round(App # Level * .60, .1);&lt;/P&gt;&lt;P&gt;A = choose(option = 'PT', R2, R3);&lt;BR /&gt;B = choose(option = 'PF', R1, A);&lt;BR /&gt;Guar = choose(Line = 'PP', B, SOMEVALUE);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 13 Feb 2014 23:01:36 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2014-02-13T23:01:36Z</dc:date>
    <item>
      <title>Choose function vs. if-then do</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Choose-function-vs-if-then-do/m-p/173978#M1714</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a piece of my program that has some nested if-then statements. I read in Rick Wicklin's "Statistical Programming with SAS/IML Software" that you should use the choose function when you are assigning values based on certain criteria. I was wondering if the choose function is always the more efficient way since I would be putting choose functions within choose functions. I know it cuts down on the amount of code written, but is there a processing time difference? An example of my code is below. Any help is appreciated. Thank you!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PP_ind = loc(Line = 'PP');&lt;/P&gt;&lt;P&gt;if ncol(PP_ind) &amp;gt; 0 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Guar[PP_ind] = round(App[PP_ind] # Level * .60, .1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PP_PF_ind = loc(Line = 'PP' &amp;amp; Option = 'PF');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ncol(PP_PF_ind) &amp;gt; 0 then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Guar[PP_PF_ind] = round(App[PP_PF_ind] # Level * .65, .1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; PP_PT_ind = loc(Line = 'PP' &amp;amp; Option = 'PT');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ncol(PP_PT_ind) &amp;gt; 0 then&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Guar[PP_PT_ind[ = round(App[PP_PT_ind] # Level * .70, .1);&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Proposed method using the choose function - not sure if it is the correct syntax because I am getting an error: "ERROR: The arguments to the built-in function are invalid. (444, 22)"&lt;/P&gt;&lt;P&gt; Guar = choose(Line = 'PP', choose(option = 'PF', round(App # Level * .65, .1), choose(option = 'PT', round(App # Level * .70, .1), round(App # Level * .60, .1))))&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Maybe my question should be - "Is it possible to put a choose function inside of another choose function?"&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Feb 2014 21:35:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Choose-function-vs-if-then-do/m-p/173978#M1714</guid>
      <dc:creator>kelchenk</dc:creator>
      <dc:date>2014-02-13T21:35:42Z</dc:date>
    </item>
    <item>
      <title>Re: Choose function vs. if-then do</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Choose-function-vs-if-then-do/m-p/173979#M1715</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, you can put a CHOOSE function inside another. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you are only doing this choice a few times, then it doesn't matter which conditional statements you use, and I'd choose the IF-THEN because it is easier to read. If this is going to be inside a big loop, then you might want to compare the performance by timing the computations. See &lt;A href="http://blogs.sas.com/content/iml/2012/12/05/remove-or-keep-which-is-faster/" title="http://blogs.sas.com/content/iml/2012/12/05/remove-or-keep-which-is-faster/"&gt; Remove or keep: Which is faster? - The DO Loop&lt;/A&gt; or Chapter 15 of &lt;EM&gt;Statistical Programming with SAS/IML Software.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regarding your nested CHOOSE construction, you are missing a final 'else'.&amp;nbsp; What happens if Line^='PP'? It should read:&lt;/P&gt;&lt;P&gt;Guar = choose(Line = 'PP', choose(...), SOMEVALUE );&lt;/P&gt;&lt;P&gt;A trick that I like to use is to precompute the nested values so that the nested CHOOSE functions aren't so hard to read. Something like this might be helpful if you 'choose' to use nested CHOOSE functions:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* possible results */&lt;BR /&gt;R1 = round(App # Level * .65, .1);&lt;BR /&gt;R2 = round(App # Level * .70, .1);&lt;BR /&gt;R3 = round(App # Level * .60, .1);&lt;/P&gt;&lt;P&gt;A = choose(option = 'PT', R2, R3);&lt;BR /&gt;B = choose(option = 'PF', R1, A);&lt;BR /&gt;Guar = choose(Line = 'PP', B, SOMEVALUE);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Feb 2014 23:01:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Choose-function-vs-if-then-do/m-p/173979#M1715</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2014-02-13T23:01:36Z</dc:date>
    </item>
  </channel>
</rss>

