<?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 GOTO statement in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/GOTO-statement/m-p/25540#M112</link>
    <description>Hello, &lt;BR /&gt;
&lt;BR /&gt;
In order to estimate mixture models i need to generate multiple random starts and estimate the local maxima of the likelihood by the expectation-maximization algorithm. Thus, i have two loops, one outer loop for a particular set of starting values and an inner loop for the EM iterations. For some bad start values the EM-iterations encounter computational problems such as singular matrices, overflows,.. This is not a problem, just discard these start values and try a new set. I try to do this as follows: &lt;BR /&gt;
&lt;BR /&gt;
onerror=" goto st; resume; ";&lt;BR /&gt;
do s=1 to n_start;&lt;BR /&gt;
 call push(onerror);&lt;BR /&gt;
 st: run start;   /*some module to generate start values*/&lt;BR /&gt;
 do e=1 to em_iterations;&lt;BR /&gt;
  run em;  /*some module to perform 1 EM-iteration*/&lt;BR /&gt;
 end;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
This however doesn't work and i get ERROR: Unresolved label: ST. I've also tried &lt;BR /&gt;
onerror=" do; goto st; resume; end;"; but that doesn't work either. &lt;BR /&gt;
&lt;BR /&gt;
Does anyone have an idea how to make this work (or knows a better way to go about this)? &lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance, &lt;BR /&gt;
&lt;BR /&gt;
Nicolas</description>
    <pubDate>Fri, 21 May 2010 12:48:00 GMT</pubDate>
    <dc:creator>nicolas_</dc:creator>
    <dc:date>2010-05-21T12:48:00Z</dc:date>
    <item>
      <title>GOTO statement</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/GOTO-statement/m-p/25540#M112</link>
      <description>Hello, &lt;BR /&gt;
&lt;BR /&gt;
In order to estimate mixture models i need to generate multiple random starts and estimate the local maxima of the likelihood by the expectation-maximization algorithm. Thus, i have two loops, one outer loop for a particular set of starting values and an inner loop for the EM iterations. For some bad start values the EM-iterations encounter computational problems such as singular matrices, overflows,.. This is not a problem, just discard these start values and try a new set. I try to do this as follows: &lt;BR /&gt;
&lt;BR /&gt;
onerror=" goto st; resume; ";&lt;BR /&gt;
do s=1 to n_start;&lt;BR /&gt;
 call push(onerror);&lt;BR /&gt;
 st: run start;   /*some module to generate start values*/&lt;BR /&gt;
 do e=1 to em_iterations;&lt;BR /&gt;
  run em;  /*some module to perform 1 EM-iteration*/&lt;BR /&gt;
 end;&lt;BR /&gt;
end;&lt;BR /&gt;
&lt;BR /&gt;
This however doesn't work and i get ERROR: Unresolved label: ST. I've also tried &lt;BR /&gt;
onerror=" do; goto st; resume; end;"; but that doesn't work either. &lt;BR /&gt;
&lt;BR /&gt;
Does anyone have an idea how to make this work (or knows a better way to go about this)? &lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance, &lt;BR /&gt;
&lt;BR /&gt;
Nicolas</description>
      <pubDate>Fri, 21 May 2010 12:48:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/GOTO-statement/m-p/25540#M112</guid>
      <dc:creator>nicolas_</dc:creator>
      <dc:date>2010-05-21T12:48:00Z</dc:date>
    </item>
    <item>
      <title>Re: GOTO statement</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/GOTO-statement/m-p/25541#M113</link>
      <description>I think the fundamental problem is that the error occurs in the EM module, but you are trying to jump to a statement outside of the module. that's why the ST label is not recognized.&lt;BR /&gt;
&lt;BR /&gt;
What I like to do is to have the module that might fail return a "return code" that can be handled by the calling routine. In the code below, I use a DO/WHILE loop to jump out of the iterative loop when the EM module fails. I then call the INIT routine and continue to the next set of starting values.&lt;BR /&gt;
&lt;BR /&gt;
proc iml;&lt;BR /&gt;
start init;&lt;BR /&gt;
  x=1;&lt;BR /&gt;
finish;&lt;BR /&gt;
&lt;BR /&gt;
start EM(args);&lt;BR /&gt;
  onError={ "if ErrorChecking then do;"&lt;BR /&gt;
            "rc = 1;"&lt;BR /&gt;
            "call push(onerror);"&lt;BR /&gt;
            "resume;"&lt;BR /&gt;
            "end;"&lt;BR /&gt;
           };&lt;BR /&gt;
  call push(onError);&lt;BR /&gt;
  rc = 0;                      /* return 0 if no error */&lt;BR /&gt;
  ErrorChecking = 1;           /* turn on error checking */&lt;BR /&gt;
  t = log(0.75-uniform(54321));/* error 25% of the time */&lt;BR /&gt;
  ErrorChecking = 0;           /* turn off error checking */&lt;BR /&gt;
  return (rc);                 /* return whether error occurred */&lt;BR /&gt;
finish;&lt;BR /&gt;
&lt;BR /&gt;
myargs = {1,2,3};&lt;BR /&gt;
run init;&lt;BR /&gt;
do s=1 to 3;&lt;BR /&gt;
  err = 0;                    /* no error */&lt;BR /&gt;
  do e=1 to 5 while(err=0);   /* exit loop on error */&lt;BR /&gt;
    err = EM(myargs);         /* perform 1 iteration*/&lt;BR /&gt;
    print s e err;&lt;BR /&gt;
  end;&lt;BR /&gt;
  if err then do;             /* error: reinitialize */&lt;BR /&gt;
     print "*** Error occurred...reinitialize ***";&lt;BR /&gt;
     run init;                /* regenerate starting values*/&lt;BR /&gt;
  end;&lt;BR /&gt;
end;</description>
      <pubDate>Mon, 24 May 2010 20:19:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/GOTO-statement/m-p/25541#M113</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2010-05-24T20:19:10Z</dc:date>
    </item>
  </channel>
</rss>

