<?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: Return multiple values using SAS/IML function when using nested functions in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Return-multiple-values-using-SAS-IML-function-when-using-nested/m-p/888963#M6020</link>
    <description>&lt;P&gt;Hello Rick&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the suggestions. Is it ok to use&lt;/P&gt;&lt;DIV&gt;Do i=1 to m;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;W[i]=Uniform(seed); &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;End;&lt;/DIV&gt;&lt;DIV&gt;instead of the ranuni which I used earlier in my code?&lt;/DIV&gt;&lt;DIV&gt;As for the second suggestion, I am not sure I understood it.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thank you&lt;/DIV&gt;</description>
    <pubDate>Fri, 11 Aug 2023 15:57:19 GMT</pubDate>
    <dc:creator>Salah</dc:creator>
    <dc:date>2023-08-11T15:57:19Z</dc:date>
    <item>
      <title>Return multiple values using SAS/IML function when using nested functions</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Return-multiple-values-using-SAS-IML-function-when-using-nested/m-p/888845#M6016</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am simulating data and calling&amp;nbsp; module function from within another module. My problem is that I need to return the vector of data that I created inside my module along with the index (q).&lt;/P&gt;&lt;P&gt;I kindly ask for your help.&lt;/P&gt;&lt;P&gt;********************************************************&lt;/P&gt;&lt;DIV&gt;proc iml;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;n=20; m=15; K=J(m,1,0); K[m]=n-m;&lt;/DIV&gt;&lt;DIV&gt;L=K;&amp;nbsp; m1=m; m2=m;&lt;/DIV&gt;&lt;DIV&gt;Theta1 =2; Theta2=5;&amp;nbsp; &amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;seed=22;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;start Uniform_p(m,R)&amp;nbsp; global(seed);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;** The Required Progressively Type-II from U(0,1);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;W=ranuni( repeat(seed,m,1) );&lt;/DIV&gt;&lt;DIV&gt;V=J(m,1,0); U=J(m,1,0);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Do i=1 to m;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Sum=0;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Do j=m-i+1 to m;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Sum=Sum+R[j];&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; End;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Sum=Sum+i;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;V[i]=W[i]**(1/Sum);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;End;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Do i=1 to m;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; U[i]=1-prod ( V[m: (m-i+1)]&amp;nbsp; &amp;nbsp;);&lt;/DIV&gt;&lt;DIV&gt;End;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Call sort (U);&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;return U;&lt;/DIV&gt;&lt;DIV&gt;Finish;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;start Adaptive(X,m,R,theta) ;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;T=X[CEIL(m/4)];&lt;/DIV&gt;&lt;DIV&gt;Do idx=1 to m-1;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; If (( X[idx] &amp;lt; T) &amp;amp; (T &amp;lt;= X[idx+1] )) then q=idx;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;End;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;If X[m]&amp;gt;T then&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Do;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;W=Uniform_p(m-q,R);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;X_m_q = T - theta*log(1-W);&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;X_Adptive= X[1:q]//X_m_q;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; End;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Do;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;q= m;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;X_Adptive=X;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;return X_Adptive; &lt;FONT color="#FF0000"&gt;* I need to return&amp;nbsp;X_Adptive ,&amp;nbsp; q&amp;nbsp; and T;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;Finish;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;X = - theta1 * log (1- uniform_p(m1,K));&lt;/DIV&gt;&lt;DIV&gt;Y = - theta2 * log (1- uniform_p(m2,L));&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;X_ADP=Adaptive(X,m1,K,theta1);&lt;/DIV&gt;&lt;DIV&gt;Y_ADP=Adaptive(Y,m2,L,theta2);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Print q&amp;nbsp; T&amp;nbsp; X&amp;nbsp; X_ADP;&lt;/DIV&gt;&lt;DIV&gt;quit;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Thu, 10 Aug 2023 19:20:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Return-multiple-values-using-SAS-IML-function-when-using-nested/m-p/888845#M6016</guid>
      <dc:creator>Salah</dc:creator>
      <dc:date>2023-08-10T19:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: Return multiple values using SAS/IML function when using nested functions</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Return-multiple-values-using-SAS-IML-function-when-using-nested/m-p/888852#M6017</link>
      <description>&lt;P&gt;One option is to return a list.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp; wrote about lists here: &lt;A href="https://blogs.sas.com/content/iml/2017/03/29/lists-sasiml.html" target="_self"&gt;https://blogs.sas.com/content/iml/2017/03/29/lists-sasiml.html&lt;/A&gt;&amp;nbsp;. In your case, you would want to return a list of two items, where the first item is the simulated vector, and the second item is the index value.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2023 20:15:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Return-multiple-values-using-SAS-IML-function-when-using-nested/m-p/888852#M6017</guid>
      <dc:creator>Mike_N</dc:creator>
      <dc:date>2023-08-10T20:15:14Z</dc:date>
    </item>
    <item>
      <title>Re: Return multiple values using SAS/IML function when using nested functions</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Return-multiple-values-using-SAS-IML-function-when-using-nested/m-p/888900#M6018</link>
      <description>&lt;P&gt;In addition to what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/439735"&gt;@Mike_N&lt;/a&gt;&amp;nbsp;says, I would gently suggest that you consider two changes to your program:&lt;/P&gt;
&lt;P&gt;1. Use the RANDGEN function instead of RANUNI. See&amp;nbsp;&lt;A href="https://blogs.sas.com/content/iml/2013/07/10/stop-using-ranuni.html" target="_blank" rel="noopener"&gt;Six reasons you should stop using the RANUNI function to generate random numbers - The DO Loop (sas.com)&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;2. Vectorize the program to achieve better performance. See&amp;nbsp;&lt;A href="https://blogs.sas.com/content/iml/2013/05/15/vectorize-computations.html" target="_blank" rel="noopener"&gt;How to vectorize computations in a matrix language - The DO Loop (sas.com)&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect&amp;nbsp;@Mike_N can help with my second suggestion if it is not clear.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2023 09:47:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Return-multiple-values-using-SAS-IML-function-when-using-nested/m-p/888900#M6018</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2023-08-11T09:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: Return multiple values using SAS/IML function when using nested functions</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Return-multiple-values-using-SAS-IML-function-when-using-nested/m-p/888962#M6019</link>
      <description>&lt;P&gt;Thank you for your suggestions. I read the article and I even went to SAS help to read more about it. However, I am not sure where to put it in my code!!&lt;/P&gt;&lt;P&gt;Inside the subroutine? and How?&lt;/P&gt;&lt;P&gt;Can you please demonstrate into my code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2023 15:45:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Return-multiple-values-using-SAS-IML-function-when-using-nested/m-p/888962#M6019</guid>
      <dc:creator>Salah</dc:creator>
      <dc:date>2023-08-11T15:45:02Z</dc:date>
    </item>
    <item>
      <title>Re: Return multiple values using SAS/IML function when using nested functions</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Return-multiple-values-using-SAS-IML-function-when-using-nested/m-p/888963#M6020</link>
      <description>&lt;P&gt;Hello Rick&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for the suggestions. Is it ok to use&lt;/P&gt;&lt;DIV&gt;Do i=1 to m;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;W[i]=Uniform(seed); &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;End;&lt;/DIV&gt;&lt;DIV&gt;instead of the ranuni which I used earlier in my code?&lt;/DIV&gt;&lt;DIV&gt;As for the second suggestion, I am not sure I understood it.&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Thank you&lt;/DIV&gt;</description>
      <pubDate>Fri, 11 Aug 2023 15:57:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Return-multiple-values-using-SAS-IML-function-when-using-nested/m-p/888963#M6020</guid>
      <dc:creator>Salah</dc:creator>
      <dc:date>2023-08-11T15:57:19Z</dc:date>
    </item>
    <item>
      <title>Re: Return multiple values using SAS/IML function when using nested functions</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Return-multiple-values-using-SAS-IML-function-when-using-nested/m-p/888966#M6021</link>
      <description>&lt;P&gt;At the end of your Adaptive module, it looks like you want to return&amp;nbsp;&lt;SPAN&gt;X_Adptive, q and t, but you are only returning X_Adptive. To return all three, you can create a list that contains those three items (see here&amp;nbsp;&lt;A href="https://blogs.sas.com/content/iml/2018/01/22/iml-lists-syntax.html" target="_self"&gt;https://blogs.sas.com/content/iml/2018/01/22/iml-lists-syntax.html&lt;/A&gt;&amp;nbsp;) and return the list from the module.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Aug 2023 16:26:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Return-multiple-values-using-SAS-IML-function-when-using-nested/m-p/888966#M6021</guid>
      <dc:creator>Mike_N</dc:creator>
      <dc:date>2023-08-11T16:26:28Z</dc:date>
    </item>
    <item>
      <title>Re: Return multiple values using SAS/IML function when using nested functions</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Return-multiple-values-using-SAS-IML-function-when-using-nested/m-p/889033#M6022</link>
      <description>&lt;P&gt;Thank you Nike_N for your help.&lt;/P&gt;&lt;P&gt;I added the list as you suggested, unfortunately the code didn't work and SAS didn't recognize the list. I am not sure if this is due to defining it inside my subroutine or something else. Please advise. The code attached below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Aug 2023 10:21:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Return-multiple-values-using-SAS-IML-function-when-using-nested/m-p/889033#M6022</guid>
      <dc:creator>Salah</dc:creator>
      <dc:date>2023-08-12T10:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: Return multiple values using SAS/IML function when using nested functions</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Return-multiple-values-using-SAS-IML-function-when-using-nested/m-p/889203#M6023</link>
      <description>&lt;P&gt;You're on the right track, but you're still returning just the vector X_Adptive from your Adaptive module. When you create the list P1 in that module, you need to include X_Adptive as an element of the list (in addition to T and q) and then return P1:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;P1 = [ X_Adptive, T, q];
return P1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And later on, note that when you call the Adaptive module, you access elements of the returned list like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;adaptiveRes = Adaptive(X,m1,K,theta1);
X_ADP = adaptiveRes$1;
T = adaptiveRes$2;
q = adaptiveRes$3;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I would also recommend reviewing the use of named lists in the above linked blog post. In the examples above, you can see I'm extracting list items using their positions (i.e.,&amp;nbsp;&lt;CODE class=" language-sas"&gt;adaptiveRes$1&lt;/CODE&gt;is the first item of the list). However, giving list items names can improve code readability. For example, in your case, you could name your list items 'X_Adaptive', 't', and 'q', and then extract those by name rather than position.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Aug 2023 15:39:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Return-multiple-values-using-SAS-IML-function-when-using-nested/m-p/889203#M6023</guid>
      <dc:creator>Mike_N</dc:creator>
      <dc:date>2023-08-14T15:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: Return multiple values using SAS/IML function when using nested functions</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Return-multiple-values-using-SAS-IML-function-when-using-nested/m-p/889205#M6024</link>
      <description>Thank you so much for your help.</description>
      <pubDate>Mon, 14 Aug 2023 16:04:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Return-multiple-values-using-SAS-IML-function-when-using-nested/m-p/889205#M6024</guid>
      <dc:creator>Salah</dc:creator>
      <dc:date>2023-08-14T16:04:39Z</dc:date>
    </item>
  </channel>
</rss>

