<?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: iml avoid error with empty matrix in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/iml-avoid-error-with-empty-matrix/m-p/338760#M3321</link>
    <description>&lt;P&gt;An easier-to-read version might be&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if all(result=.) then 
   handle_all_missing;
else
   b = min(...);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 07 Mar 2017 11:23:01 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2017-03-07T11:23:01Z</dc:date>
    <item>
      <title>iml avoid error with empty matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/iml-avoid-error-with-empty-matrix/m-p/337994#M3311</link>
      <description>&lt;P&gt;I run into an error while assigning a scalar with the loc function.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Everything works fine until I do not meet the condition in the loc.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Break_even = MIN(loc(result &amp;gt; 0));&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This returns the month when the project breaks even. But if the project fails to do so, the code stops executing because the matrix Break_even isn't set.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I use this inside a Do Loop and I have tried to control this situation with If-then.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;without success so far.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How do I handle situations like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help, bye, Arne&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 20:19:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/iml-avoid-error-with-empty-matrix/m-p/337994#M3311</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2017-03-03T20:19:38Z</dc:date>
    </item>
    <item>
      <title>Re: iml avoid error with empty matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/iml-avoid-error-with-empty-matrix/m-p/338010#M3312</link>
      <description>&lt;P&gt;using the LOC function as an index without checking&amp;nbsp;that the return value is nonempty is jokingly called "using a naked loc". &lt;A href="http://blogs.sas.com/content/iml/2012/11/19/beware-the-naked-loc.html" target="_self"&gt;Read about the naked loc and how to test for the condition.&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The typically usage is&lt;/P&gt;
&lt;P&gt;idx&amp;nbsp;= loc(result &amp;gt; 0);&lt;/P&gt;
&lt;P&gt;if ncol(idx) &amp;gt; 0 then&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;Break_even = min(idx);&lt;/P&gt;
&lt;P&gt;else&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;/* handle the case where no result is positive */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How you handle the empty result is up to you. You might assign a missing value, abort the program, assign a default value, and so forth.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 21:07:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/iml-avoid-error-with-empty-matrix/m-p/338010#M3312</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-03-03T21:07:30Z</dc:date>
    </item>
    <item>
      <title>Re: iml avoid error with empty matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/iml-avoid-error-with-empty-matrix/m-p/338036#M3313</link>
      <description>&lt;P&gt;Thank you very much.&lt;/P&gt;
&lt;P&gt;I have applied your proposal&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BUT I still get the error message&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: ELSE does not follow IF statement at line=...&lt;/P&gt;
&lt;P&gt;ERROR: END does not occur within DO group at line...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As I had mentioned, I use it within a Do Loop and making use of a SUBMIT statement I call SGPLOT to produce 64 graphs according to my different scenerios. It works perfectly except this abort when the there's no break even &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&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;</description>
      <pubDate>Fri, 03 Mar 2017 22:03:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/iml-avoid-error-with-empty-matrix/m-p/338036#M3313</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2017-03-03T22:03:47Z</dc:date>
    </item>
    <item>
      <title>Re: iml avoid error with empty matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/iml-avoid-error-with-empty-matrix/m-p/338039#M3314</link>
      <description>&lt;P&gt;The errors indicate that you did not implement the IF-THEN/ELSE condition correctly. &amp;nbsp;If you post the relevant portion of your log, someone will be able to find the mistake.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Mar 2017 22:09:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/iml-avoid-error-with-empty-matrix/m-p/338039#M3314</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-03-03T22:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: iml avoid error with empty matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/iml-avoid-error-with-empty-matrix/m-p/338088#M3315</link>
      <description>&lt;P&gt;OR Try any()&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if any(result &amp;gt; 0) then Break_even = MIN(loc(result &amp;gt; 0));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 04 Mar 2017 03:20:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/iml-avoid-error-with-empty-matrix/m-p/338088#M3315</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-03-04T03:20:15Z</dc:date>
    </item>
    <item>
      <title>Re: iml avoid error with empty matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/iml-avoid-error-with-empty-matrix/m-p/338420#M3316</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;It works except when I run an if-then statement&amp;nbsp;within a do-loop.&lt;/P&gt;
&lt;P&gt;Do I&amp;nbsp;have to obey&amp;nbsp;something special when I place an if-then logic within a do-loop?&lt;/P&gt;
&lt;P&gt;The do-loop&amp;nbsp;executes fine without if-then and the same is true for the inverse.&lt;/P&gt;
&lt;P&gt;But both togehther gives error.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 11:50:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/iml-avoid-error-with-empty-matrix/m-p/338420#M3316</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2017-03-06T11:50:00Z</dc:date>
    </item>
    <item>
      <title>Re: iml avoid error with empty matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/iml-avoid-error-with-empty-matrix/m-p/338424#M3317</link>
      <description>&lt;P&gt;No, the syntax for an IF-THEN statement inside a DO loop is the same as outside. &amp;nbsp;You might have missing or mismatched DO-END statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please post the portion of the SAS log that gives the source and error messages.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Mar 2017 12:17:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/iml-avoid-error-with-empty-matrix/m-p/338424#M3317</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-03-06T12:17:47Z</dc:date>
    </item>
    <item>
      <title>Re: iml avoid error with empty matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/iml-avoid-error-with-empty-matrix/m-p/338745#M3318</link>
      <description>&lt;P&gt;If you know the size&amp;nbsp;of the matrix result, or can easily&amp;nbsp;work it out,&amp;nbsp; then another way might be to&amp;nbsp;use CHOOSE.&amp;nbsp; Here I am assuming result is a row vector with 12 elements, one for each month.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   b = min( choose(result&amp;gt;0, 1:12, . ));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I was thinking I would get a missing value returned when all the elements of result are&amp;nbsp;negative,&amp;nbsp;however I get the largest representable floating point.&amp;nbsp;&amp;nbsp;&amp;nbsp; This is in 13.1&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 10:37:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/iml-avoid-error-with-empty-matrix/m-p/338745#M3318</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2017-03-07T10:37:40Z</dc:date>
    </item>
    <item>
      <title>Re: iml avoid error with empty matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/iml-avoid-error-with-empty-matrix/m-p/338751#M3319</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/9374"&gt;@IanWakeling&lt;/a&gt;&amp;nbsp;Since the MIN function ignores missing values,&amp;nbsp;you are&amp;nbsp;getting the default initialized value, as documented. See the &lt;A href="http://support.sas.com/documentation/cdl/en/imlug/68150/HTML/default/viewer.htm#imlug_langref_sect257.htm" target="_self"&gt;second paragraph of the doc of the MIN function.&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 10:51:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/iml-avoid-error-with-empty-matrix/m-p/338751#M3319</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-03-07T10:51:04Z</dc:date>
    </item>
    <item>
      <title>Re: iml avoid error with empty matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/iml-avoid-error-with-empty-matrix/m-p/338756#M3320</link>
      <description>&lt;P&gt;Thanks Rick.&amp;nbsp;&amp;nbsp; I should have checked the docs more carefully.&amp;nbsp;&amp;nbsp;I think I will stop there, as adding something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if b &amp;lt; constant('BIG') then...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will&amp;nbsp;start to look very confusing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 11:09:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/iml-avoid-error-with-empty-matrix/m-p/338756#M3320</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2017-03-07T11:09:47Z</dc:date>
    </item>
    <item>
      <title>Re: iml avoid error with empty matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/iml-avoid-error-with-empty-matrix/m-p/338760#M3321</link>
      <description>&lt;P&gt;An easier-to-read version might be&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if all(result=.) then 
   handle_all_missing;
else
   b = min(...);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Mar 2017 11:23:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/iml-avoid-error-with-empty-matrix/m-p/338760#M3321</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-03-07T11:23:01Z</dc:date>
    </item>
  </channel>
</rss>

