<?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 Referencing global matrix inside function in proc iml in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Referencing-global-matrix-inside-function-in-proc-iml/m-p/317360#M3115</link>
    <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to proc iml (and SAS in general) and am attempting to use proc iml optimization. Unfortunately, I am having trouble referencing a matrix that I created. The idea of my code is below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc iml;&lt;/P&gt;&lt;P&gt;use mysasdataset;&lt;/P&gt;&lt;P&gt;read all var into VARS;&lt;/P&gt;&lt;P&gt;close mysasdataset;&lt;/P&gt;&lt;P&gt;concent = VARS[,1];&lt;/P&gt;&lt;P&gt;print concent;&lt;/P&gt;&lt;P&gt;show names;&lt;/P&gt;&lt;P&gt;start F_HRCOPT(x);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; f=concent*matrix&amp;nbsp; (some other stuff follows here; the matrix to which I refer is 1x1).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return f;&lt;/P&gt;&lt;P&gt;finish F_HRCOPT;&lt;/P&gt;&lt;P&gt;...continue with code...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The issue that I'm having is that when I use "show names;" it does state that the variable concent has been created and that its dimensions are Nx1 (which is exactly what I want; picture attached).&amp;nbsp; However, when I look at my SAS log it indicates that concent is empty (0x0). Any ideas why? Do I have to reference the matrix in a special way inside of the function? My thoughts are that the matrix "concent" should be a global matrix since it's defined outside of the function, which leads me to believe that I should be able to reference it inside of the function. Any insight would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;JMM&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/13232iEC85E8614D562BDF/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="Screen Shot 2016-12-07 at 11.17.02 AM.png" title="Screen Shot 2016-12-07 at 11.17.02 AM.png" /&gt;</description>
    <pubDate>Wed, 07 Dec 2016 16:18:35 GMT</pubDate>
    <dc:creator>imamathgk</dc:creator>
    <dc:date>2016-12-07T16:18:35Z</dc:date>
    <item>
      <title>Referencing global matrix inside function in proc iml</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Referencing-global-matrix-inside-function-in-proc-iml/m-p/317360#M3115</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to proc iml (and SAS in general) and am attempting to use proc iml optimization. Unfortunately, I am having trouble referencing a matrix that I created. The idea of my code is below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc iml;&lt;/P&gt;&lt;P&gt;use mysasdataset;&lt;/P&gt;&lt;P&gt;read all var into VARS;&lt;/P&gt;&lt;P&gt;close mysasdataset;&lt;/P&gt;&lt;P&gt;concent = VARS[,1];&lt;/P&gt;&lt;P&gt;print concent;&lt;/P&gt;&lt;P&gt;show names;&lt;/P&gt;&lt;P&gt;start F_HRCOPT(x);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; f=concent*matrix&amp;nbsp; (some other stuff follows here; the matrix to which I refer is 1x1).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return f;&lt;/P&gt;&lt;P&gt;finish F_HRCOPT;&lt;/P&gt;&lt;P&gt;...continue with code...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The issue that I'm having is that when I use "show names;" it does state that the variable concent has been created and that its dimensions are Nx1 (which is exactly what I want; picture attached).&amp;nbsp; However, when I look at my SAS log it indicates that concent is empty (0x0). Any ideas why? Do I have to reference the matrix in a special way inside of the function? My thoughts are that the matrix "concent" should be a global matrix since it's defined outside of the function, which leads me to believe that I should be able to reference it inside of the function. Any insight would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;JMM&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/13232iEC85E8614D562BDF/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="Screen Shot 2016-12-07 at 11.17.02 AM.png" title="Screen Shot 2016-12-07 at 11.17.02 AM.png" /&gt;</description>
      <pubDate>Wed, 07 Dec 2016 16:18:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Referencing-global-matrix-inside-function-in-proc-iml/m-p/317360#M3115</guid>
      <dc:creator>imamathgk</dc:creator>
      <dc:date>2016-12-07T16:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing global matrix inside function in proc iml</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Referencing-global-matrix-inside-function-in-proc-iml/m-p/317368#M3116</link>
      <description>&lt;P&gt;The problem is that SAS/IML functions use a local symbol table, so although the CONCENT matrix is known in the main (parent) environment, that symbol is not known to the function. &amp;nbsp;For a more comprehensize explanation, see the article &lt;A href="http://blogs.sas.com/content/iml/2013/04/29/understanding-local-and-global-variables-in-the-sasiml-language.html" target="_self"&gt;"Understanding local and global variables in the SAS/IML language."&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In short, you must pass in matrices to function via the argument list of declare them to be a global variable by using the GLOBAL clause.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you intend to do some optimization in SAS/IML, I recommend the following articles:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://blogs.sas.com/content/iml/2011/10/12/maximum-likelihood-estimation-in-sasiml.html" target="_self"&gt;Maximum likelihood estimation in SAS/IML&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://blogs.sas.com/content/iml/2016/05/11/tips-before-optimization.html" target="_self"&gt;Ten tips before you run an optimization&lt;/A&gt;&lt;/LI&gt;
&lt;LI style="list-style-type: none;"&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;You might also want to keep this documentation handy:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/imlug/68150/HTML/default/viewer.htm#imlug_nonlinearoptexpls_toc.htm" target="_self"&gt;The documentation on modules and function&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/imlug/68150/HTML/default/viewer.htm#imlug_nonlinearoptexpls_toc.htm" target="_self"&gt;The documentation on optimization&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Wed, 07 Dec 2016 16:30:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Referencing-global-matrix-inside-function-in-proc-iml/m-p/317368#M3116</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2016-12-07T16:30:33Z</dc:date>
    </item>
    <item>
      <title>Re: Referencing global matrix inside function in proc iml</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Referencing-global-matrix-inside-function-in-proc-iml/m-p/317376#M3117</link>
      <description>&lt;P&gt;I thought that might be the case! Thank you! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Dec 2016 16:48:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Referencing-global-matrix-inside-function-in-proc-iml/m-p/317376#M3117</guid>
      <dc:creator>imamathgk</dc:creator>
      <dc:date>2016-12-07T16:48:08Z</dc:date>
    </item>
  </channel>
</rss>

