<?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: ExpandGrid function - passing dynamic parameters in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/ExpandGrid-function-passing-dynamic-parameters/m-p/475768#M4271</link>
    <description>&lt;P&gt;Yes. I suggest CALL EXECUTE. You can build up the EXPANDGRID arguments dynamically:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
x1 = 1:2;
x2 = 1:3;
x3 = -1:1;

condition = 0; /* set =1 for true */
str = "g = expandgrid(x1, x2";
if condition then 
   stmt = str + ", x3);";
else 
   stmt = str + ");";
call execute(stmt);
print g;&lt;/CODE&gt;&lt;/PRE&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>Thu, 05 Jul 2018 18:27:59 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2018-07-05T18:27:59Z</dc:date>
    <item>
      <title>ExpandGrid function - passing dynamic parameters</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/ExpandGrid-function-passing-dynamic-parameters/m-p/402861#M3754</link>
      <description>&lt;P&gt;I'm trying to use the ExpandGrid function on several vertical vectors without knowing the number of vectors when the code is written, The&amp;nbsp;example below shows a use case that creates 4 matrices (from A to D) each consisting of the cartesian product of two vectors. However, at run time there may be more (or fewer) matrices to create&amp;nbsp; or vectors in each matrix. I know ExpandGrid requires between 2 and 15 vectors, so I'll make sure these limits are not exceeded.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can this be written dynamically?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
Var_1_A = {1, 4, 5, 7};
Var_1_B = {3, 4, 2};
Var_1_C = {10, 11};

Var_2_A = {11, 0, 2};
Var_2_B = {13, 2, 2, 5, 9};
Var_2_C = {10, 11};

/* Hard coded*/
CP_A = ExpangrGrid(Var_1_A, Var_2_A);
CP_B = ExpangrGrid(Var_1_B, Var_2_B);
CP_C = ExpangrGrid(Var_1_C, Var_2_C);
CP_D = ExpangrGrid(Var_1_D, Var_2_D);

quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2017 17:21:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/ExpandGrid-function-passing-dynamic-parameters/m-p/402861#M3754</guid>
      <dc:creator>MDaniel</dc:creator>
      <dc:date>2017-10-10T17:21:34Z</dc:date>
    </item>
    <item>
      <title>Re: ExpandGrid function - passing dynamic parameters</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/ExpandGrid-function-passing-dynamic-parameters/m-p/402867#M3756</link>
      <description>&lt;P&gt;Do you need all grids SIMULTANEOUSLY, or do you just need to loop over all combinations, generate the grid, do something with the&amp;nbsp;grid, and then go on to the next combination?&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2017 17:25:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/ExpandGrid-function-passing-dynamic-parameters/m-p/402867#M3756</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-10-10T17:25:34Z</dc:date>
    </item>
    <item>
      <title>Re: ExpandGrid function - passing dynamic parameters</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/ExpandGrid-function-passing-dynamic-parameters/m-p/402874#M3757</link>
      <description>&lt;P&gt;One way is to &lt;A href="https://blogs.sas.com/content/iml/2011/03/23/indirect-assignment-how-to-create-and-use-matrices-named-x1-x2-xn.html" target="_self"&gt;use indirect assignment to iterate over the names of the variables&lt;/A&gt; that hold the data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
X1_1 = {1, 4, 5, 7};
X1_2 = {3, 4, 2};
X1_3 = {10, 11};

X2_1 = {11, 0, 2};
X2_2 = {13, 2, 2, 5, 9};
X2_3 = {10, 11};

/* create array of variable names for X and Y */
Vars1 = "x1_1":"x1_3";
Vars2 = "x2_1":"x2_3";

/* Loop over names of arrays. Use indirect assignment to 
   retreive information into temporary arrays X and Y
   https://blogs.sas.com/content/iml/2011/03/23/indirect-assignment-how-to-create-and-use-matrices-named-x1-x2-xn.html
*/
do i = 1 to ncol(Vars1);
   X = value( Vars1[i] );
	Y = value( Vars2[i] );
   G = expandgrid(X, Y);
	/* do something with G */
	msg = "Grid has " + char(nrow(G),2) + " pairs";
	print i msg;
end;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Oct 2017 17:36:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/ExpandGrid-function-passing-dynamic-parameters/m-p/402874#M3757</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-10-10T17:36:17Z</dc:date>
    </item>
    <item>
      <title>Re: ExpandGrid function - passing dynamic parameters</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/ExpandGrid-function-passing-dynamic-parameters/m-p/403189#M3758</link>
      <description>&lt;P&gt;If could make two datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
input id value1;
cards;
1 1
1 4
1 5
1 7
2 3
2 4
2 2
3 10
3 11
;
run;

data y;
input id value2;
cards;
1 11
1 0
1 2
2 13
2 2
2 2
2 5
2 9
3 10
3 11
;
run;

proc sql;
select x.*,value2
 from x,y
  where x.id=y.id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 11 Oct 2017 14:40:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/ExpandGrid-function-passing-dynamic-parameters/m-p/403189#M3758</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-10-11T14:40:31Z</dc:date>
    </item>
    <item>
      <title>Re: ExpandGrid function - passing dynamic parameters</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/ExpandGrid-function-passing-dynamic-parameters/m-p/475753#M4268</link>
      <description>How Do I grow the expandgrid arguments conditionally?&lt;BR /&gt;Sometimes I need&lt;BR /&gt;Expandgrid(X1_1, X1_2) &lt;BR /&gt;And some condition met I want&lt;BR /&gt;Expandgrid(X1_1, X1_2, X1_3)</description>
      <pubDate>Thu, 05 Jul 2018 17:59:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/ExpandGrid-function-passing-dynamic-parameters/m-p/475753#M4268</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2018-07-05T17:59:57Z</dc:date>
    </item>
    <item>
      <title>Re: ExpandGrid function - passing dynamic parameters</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/ExpandGrid-function-passing-dynamic-parameters/m-p/475759#M4269</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if condition1 then 
   g = Expandgrid(X1_1, X1_2);
else
   g = Expandgrid(X1_1, X1_2, X1_3);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 05 Jul 2018 18:08:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/ExpandGrid-function-passing-dynamic-parameters/m-p/475759#M4269</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-07-05T18:08:42Z</dc:date>
    </item>
    <item>
      <title>Re: ExpandGrid function - passing dynamic parameters</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/ExpandGrid-function-passing-dynamic-parameters/m-p/475761#M4270</link>
      <description>Ok, but is there a way to execute a iml code line thorough a concatenated string or by the use of a macro variable?</description>
      <pubDate>Thu, 05 Jul 2018 18:13:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/ExpandGrid-function-passing-dynamic-parameters/m-p/475761#M4270</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2018-07-05T18:13:54Z</dc:date>
    </item>
    <item>
      <title>Re: ExpandGrid function - passing dynamic parameters</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/ExpandGrid-function-passing-dynamic-parameters/m-p/475768#M4271</link>
      <description>&lt;P&gt;Yes. I suggest CALL EXECUTE. You can build up the EXPANDGRID arguments dynamically:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
x1 = 1:2;
x2 = 1:3;
x3 = -1:1;

condition = 0; /* set =1 for true */
str = "g = expandgrid(x1, x2";
if condition then 
   stmt = str + ", x3);";
else 
   stmt = str + ");";
call execute(stmt);
print g;&lt;/CODE&gt;&lt;/PRE&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>Thu, 05 Jul 2018 18:27:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/ExpandGrid-function-passing-dynamic-parameters/m-p/475768#M4271</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2018-07-05T18:27:59Z</dc:date>
    </item>
    <item>
      <title>Re: ExpandGrid function - passing dynamic parameters</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/ExpandGrid-function-passing-dynamic-parameters/m-p/475774#M4272</link>
      <description>Thank you Rick</description>
      <pubDate>Thu, 05 Jul 2018 18:46:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/ExpandGrid-function-passing-dynamic-parameters/m-p/475774#M4272</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2018-07-05T18:46:42Z</dc:date>
    </item>
  </channel>
</rss>

