<?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: How to generate all positive/negative permutations of a one-row matrix in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-generate-all-positive-negative-permutations-of-a-one-row/m-p/940369#M6265</link>
    <description>Thank you. I recognize this as a valid approach to the test as opposed to whatever was originally in the slides I inherited.</description>
    <pubDate>Wed, 21 Aug 2024 18:36:29 GMT</pubDate>
    <dc:creator>schuelke_wu</dc:creator>
    <dc:date>2024-08-21T18:36:29Z</dc:date>
    <item>
      <title>How to generate all positive/negative permutations of a one-row matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-generate-all-positive-negative-permutations-of-a-one-row/m-p/938982#M6251</link>
      <description>&lt;P&gt;I am somewhat new to SAS programming and am attempting to code up a permutation test for a dependent sample test situation using the difference of the observations from two groups. I would like to simplify and generalize my code by developing a macro similar to the `allperm()` function but instead of using the difference values themselves, this macro would output permutations using a negative or positive version of each difference value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, let's say the data look like this where four subjects are each measured twice (once in each of two conditions):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;data one;&lt;/P&gt;&lt;P&gt;input sub y1 y2;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1 244 225&lt;/P&gt;&lt;P&gt;2 255 247&lt;/P&gt;&lt;P&gt;3 253 249&lt;/P&gt;&lt;P&gt;4 253 254&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Because the permutation test need only use the difference of the observations, we can compute that as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;data two;&lt;/P&gt;&lt;P&gt;set two;&lt;/P&gt;&lt;P&gt;d = y1 - y2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then the test could be performed with the following IML code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;proc iml;&lt;/P&gt;&lt;P&gt;use two;&lt;/P&gt;&lt;P&gt;read all var "d" into Y;&lt;/P&gt;&lt;P&gt;close;&lt;/P&gt;&lt;P&gt;N = 2**nrow(Y);&lt;/P&gt;&lt;P&gt;S = j(N, 1, .);&lt;/P&gt;&lt;P&gt;i = 1;&lt;/P&gt;&lt;P&gt;do a = 1 to 2;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do b = 1 to 2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do c = 1 to 2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do d = 1 to 2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; P = j(4, 1, .);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; P[1] = 2 * (a - 1.5) * Y[1];&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; P[2] = 2 * (b - 1.5) * Y[2];&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; P[3] = 2 * (c - 1.5) * Y[3];&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; P[4] = 2 * (d - 1.5) * Y[4];&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; S[i] = abs(mean(P));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i = i + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;E = 0;&lt;/P&gt;&lt;P&gt;do i = 1 to N;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if S[i] &amp;gt;= mean(Y) then E = E + 1;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;print(E / N);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As stated in the introduction, I would like to write a macro to replace the nested do loops similar to what the `allperm()` function does. This function should be generalized in the sense that it would work for a one-dimensional matrix of any length.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here are some example input and desired outputs where the difference values are Y = {19 8 4 -1};&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;signperm(Y, 1) =&amp;gt; {-19 -8 -4 1} /* first iteration produces the "negative" versions of the input */&lt;/P&gt;&lt;P&gt;signperm(Y, 2) =&amp;gt; {-19 -8 -4 -1}&amp;nbsp; /* because the later values change sign more rapidly, the second iteration produces the "positive" version of the last value */&lt;BR /&gt;signperm(Y, 4) =&amp;gt; {-19 -8 4 -1}&lt;BR /&gt;signperm(Y, &lt;span class="lia-unicode-emoji" title=":smiling_face_with_sunglasses:"&gt;😎&lt;/span&gt; =&amp;gt; {-19 8 4 -1}&lt;/P&gt;&lt;P&gt;signperm(Y, 16) =&amp;gt; {19, 8, 4, -1} /* the last iteration produces all the "positive" versions of the input */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I suspect a recursive macro would be in order, but I keep getting tripped up when writing the macro syntax.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Aug 2024 18:32:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-generate-all-positive-negative-permutations-of-a-one-row/m-p/938982#M6251</guid>
      <dc:creator>schuelke_wu</dc:creator>
      <dc:date>2024-08-12T18:32:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate all positive/negative permutations of an a one-row matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-generate-all-positive-negative-permutations-of-a-one-row/m-p/938983#M6252</link>
      <description>&lt;P&gt;Have moved this to SAS/IML board.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL class="lia-list-style-type-square"&gt;
&lt;LI&gt;Permutation tests and independent sorting of data &lt;BR /&gt;By Rick Wicklin on The DO Loop June 7, 2021&lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/iml/2021/06/07/permutation-tests-sorting-data.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2021/06/07/permutation-tests-sorting-data.html&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;SAS Global Forum 2015 -- Paper 2440-2015&lt;BR /&gt;Permit Me to Permute: A Basic Introduction to Permutation Tests with SAS/IML®&lt;BR /&gt;John Vickery, North Carolina State University&lt;BR /&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings15/2440-2015.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings15/2440-2015.pdf&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;A SAS/IML algorithm for an exact permutation test&lt;BR /&gt;&lt;A href="https://www.egms.de/static/de/journals/mibe/2009-5/mibe000092.shtml" target="_blank"&gt;https://www.egms.de/static/de/journals/mibe/2009-5/mibe000092.shtml&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Mon, 12 Aug 2024 15:59:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-generate-all-positive-negative-permutations-of-a-one-row/m-p/938983#M6252</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2024-08-12T15:59:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate all positive/negative permutations of an a one-row matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-generate-all-positive-negative-permutations-of-a-one-row/m-p/938985#M6253</link>
      <description>&lt;P&gt;Thank you for moving this question to an appropriate board, and thank you for the references.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had already come across the first two, and while they are helpful, they are building a reference distribution by resampling the permutations as opposed to calculating an exact reference distribution.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The third I had not seen before, and it looks promising in terms of its `perm()` function definition.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Aug 2024 16:26:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-generate-all-positive-negative-permutations-of-a-one-row/m-p/938985#M6253</guid>
      <dc:creator>schuelke_wu</dc:creator>
      <dc:date>2024-08-12T16:26:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate all positive/negative permutations of an a one-row matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-generate-all-positive-negative-permutations-of-a-one-row/m-p/939005#M6254</link>
      <description>&lt;P&gt;Do you have a reference for the statistical test you are trying to compute? This kind of permutation test is unfamiliar to me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;gt;&amp;nbsp;This function should be generalized in the sense that it would work for a one-dimensional matrix of any length.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your code includes the statement&amp;nbsp; &lt;STRONG&gt;N = 2**nrow(Y)&lt;/STRONG&gt;, so you already understand that for a vector of length n, there are N = 2^n ways to vary the +/- signs of each entry. Thus, this algorithm won't work for arbitrarily large data. When the size of the data exceeds 20, your method is examining more than 2^20 &amp;gt; 1 million combinations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A few suggestions:&lt;BR /&gt;1. You don't want to write a macro. You want to write a SAS IML module:&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;A href="https://blogs.sas.com/content/iml/2015/06/17/everything-about-modules.html" target="_blank"&gt;Everything you wanted to know about writing SAS/IML modules - The DO Loop&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/imlug/imlug_programstatements_sect010.htm" target="_blank"&gt;SAS Help Center: Statements That Define and Execute Modules&lt;/A&gt;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;2. You don't want all permutations. What you want is vectors of length 4 that include all COMBINATIONS of +/-1. There are 4! = 24 permutations of 4 elements, but you want the 2^4 = 16 vectors that contain all combinations of +/-1. See &lt;A href="https://blogs.sas.com/content/iml/2011/01/05/creating-a-matrix-with-all-combinations-of-zeros-and-ones.html" target="_blank"&gt;Creating a matrix with all combinations of zeros and ones - The DO Loop (sas.com)&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;3. The easiest way to generate all 4-element vectors of +/-1 is to use the EXPANDGRID function, like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; proc iml;
P = expandgrid( {-1 1}, {-1 1}, {-1 1}, {-1 1} );
print P;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;4. You're four nested loops are not necessary. Instead, loop over the rows of the P matrix. If you are familiar with matrix-vector computations, you can actually use a matrix expression to compute all signed combinations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's how you solve the problem for a data set that has 4 pairs. I'll wait until I get the algorithm reference/citation before I think about generalizing the problem:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
use two;
read all var "d" into Y;
close;

V = expandgrid( {-1 1}, {-1 1}, {-1 1}, {-1 1} );
N = nrow(V);
P = V` # Y;       /* elementwise multiplication of rows */
S = abs(mean(P)); /* mean of each column */
print S , (mean(Y))[L='mean(Y)'];;
E = sum(S &amp;gt;= mean(Y));
print E N (E/N)[L='ratio'];&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Aug 2024 18:11:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-generate-all-positive-negative-permutations-of-a-one-row/m-p/939005#M6254</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2024-08-12T18:11:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate all positive/negative permutations of an a one-row matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-generate-all-positive-negative-permutations-of-a-one-row/m-p/939014#M6255</link>
      <description>&lt;P&gt;I was working on updating some inherited presentation slides, but your request for a reference made me realize that this testing approach may not be entirely correct. The examples that I do find all perform repeated resampling of exchanged difference scores as opposed to only a single sample of each possible combination of exchanged difference scores. In other words, the reference distribution from the examples is made up of thousands of resamples as opposed to only one sample of each of the 16 combinations of interest in the case of four pairs of observations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That said, I am still interested in this problem if only to learn more about programming in SAS.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Responses to suggestions:&lt;/P&gt;&lt;P&gt;1. Yes, I figured out that I am perhaps more interested in writing a SAS IML module than a macro after posting the question. Thank you for the references - especially your blog post as it presents much of the basic information I was after in a clear way.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2. You are correct, I am only interested in the 2^4 = 16 combinations for this example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. I considered EXPANDGRID, but note that its use is dependent on the size of the difference vector. For difference vectors of length 4 one can call as you did&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;proc iml;
P = expandgrid( {-1 1}, {-1 1}, {-1 1}, {-1 1} );
print P;&lt;/LI-CODE&gt;&lt;P&gt;However, if the difference vector were instead of length 3, we would need to call the function with one less argument:&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;proc iml;
P = expandgrid( {-1 1}, {-1 1}, {-1 1} );
print P;&lt;/LI-CODE&gt;&lt;P&gt;This would be a limiting factor to make the code more generalizable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;4. Thank you for the example solution. It is much cleaner and more compact than my work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A note on large data:&lt;/P&gt;&lt;P&gt;One of my intents here was to trade memory efficiency for computational inefficiency. That is instead of computing the entire combination matrix in one go and holding it entirely in memory, I could instead compute each row of the matrix as needed and only hold the average differences in memory.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Followup questions:&lt;/P&gt;&lt;P&gt;1. Do you then think it necessary to perform the repeated resampling as per examples, or can one just use each combination a single time? (This may be better asked at stackexchange)&lt;/P&gt;&lt;P&gt;2. Is there some way to call EXPANDGRID with a varying number of arguments?&lt;/P&gt;&lt;P&gt;3. Do you think there is any value here to trading memory efficiency for computational inefficiency?&lt;/P&gt;</description>
      <pubDate>Mon, 12 Aug 2024 19:54:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-generate-all-positive-negative-permutations-of-a-one-row/m-p/939014#M6255</guid>
      <dc:creator>schuelke_wu</dc:creator>
      <dc:date>2024-08-12T19:54:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate all positive/negative permutations of a one-row matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-generate-all-positive-negative-permutations-of-a-one-row/m-p/939030#M6256</link>
      <description>&lt;P&gt;I don't see anything at anywhere in your question has something with&amp;nbsp;permutations .&lt;/P&gt;
&lt;P&gt;You just want change its sign +/- ?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data one;
input sub y1 y2;
datalines;
1 244 225
2 255 247
3 253 249
4 253 254
;
run;

data two;
set one;
d = y1 - y2;
run;

proc iml;
use two nobs n;
read all var {d} into Y;
close;
y=t(y);
t=j(n+1,n,-1);
t[loc((row(t)+col(t))&amp;gt;(n+1))]=1;
want=y#t;
print want;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ksharp_0-1723514215159.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/99205i119FE225348E8507/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1723514215159.png" alt="Ksharp_0-1723514215159.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2024 01:57:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-generate-all-positive-negative-permutations-of-a-one-row/m-p/939030#M6256</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2024-08-13T01:57:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate all positive/negative permutations of an a one-row matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-generate-all-positive-negative-permutations-of-a-one-row/m-p/939043#M6257</link>
      <description>&lt;P&gt;&lt;FONT color="#FF0000"&gt;2. Is there some way to call EXPANDGRID with a varying number of arguments?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could possibly build the the command that you want in a string and then use 'call execute'.&amp;nbsp; But I note that what you want is essentially counting in binary, so you could create an IML module for this as follows :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
  start binmat(p);
    a = 0:(2##p - 1);
    b = cshape(putn(a, cat("binary",char(p),".")), 2##p, p, 1);
    return( 2#(num(b) - 0.5) );
  finish;
  print (binmat(5)) [format=2.0];
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2024 08:39:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-generate-all-positive-negative-permutations-of-a-one-row/m-p/939043#M6257</guid>
      <dc:creator>IanWakeling</dc:creator>
      <dc:date>2024-08-13T08:39:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate all positive/negative permutations of an a one-row matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-generate-all-positive-negative-permutations-of-a-one-row/m-p/939050#M6258</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt; 1. Do you then think it necessary to perform the repeated resampling as per examples, or can one just use each combination a single time? (This may be better asked at stackexchange)&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Statistical tests that are computationally expensive come in two forms. The exact test will examine the exact sampling distribution of a statistic by using all possible combinations/permutations and obtain an exact p-value for the test. The Monte Carlo estimate of that test will consider a large number of random&amp;nbsp;combinations/permutations to obtain an approximate sampling distribution and an exact p-value. For an example and discussion, see&amp;nbsp;&lt;A href="https://blogs.sas.com/content/iml/2015/10/28/simulation-exact-tables.html" target="_blank"&gt;Monte Carlo simulation for contingency tables in SAS - The DO Loop&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can't advise you on how to proceed because I do not know what test you are running, or what the distribution of the statistic is. Reference?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;2. Is there some way to call EXPANDGRID with a varying number of arguments?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes. Sure, anytime you want to "write SAS code that writes some SAS code," there are two options: CALL EXECUTE or SAS macro. Ian suggested CALL EXECUTE. Here is an example that uses the macro language:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data two;
set one nobs=n;   /* get sample size */
d = y1 - y2;
call symputx("nobs", n); /* put it in a macro variable */
run;

/* create a comma separated list that repeats an argument n times */
%macro ListVal(v, nTimes);
%do i = 1 %to %eval(&amp;amp;nTimes-1);
   &amp;amp;v,
%end;
   &amp;amp;v
%mend;

proc iml;
s = "%ListVal({-1 1}, &amp;amp;nobs)";  /* view the result */
print s;
/* use it in ExpandGrid */
v = expandgrid( %ListVal({-1 1}, &amp;amp;nobs) );
print v;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;EM&gt;&amp;gt; 3. Do you think there is any value here to trading memory efficiency for computational inefficiency?&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;An efficient IML program will vectorize operations (which means, turn them into linear algebra operations) and will avoid lots of loops over elements of vectors. So, in general, I would avoid the programming method that you are proposing. If memory is an issue, you can sometimes refactor a memory-intensive operation to use block computations. But I do not suggest that you start there. First, define your problem, explain the method you are trying to use, and write a program that works efficiently on small data.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2024 09:54:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-generate-all-positive-negative-permutations-of-a-one-row/m-p/939050#M6258</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2024-08-13T09:54:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate all positive/negative permutations of a one-row matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-generate-all-positive-negative-permutations-of-a-one-row/m-p/939054#M6259</link>
      <description>&lt;P&gt;In thinking about your problem, I was reminded of a paper I wrote in which I discuss the permutation test:&amp;nbsp;&lt;A href="https://support.sas.com/resources/papers/proceedings10/329-2010.pdf" target="_blank"&gt;329-2010: Rediscovering SAS/IML® Software: Modern Data Analysis for the Practicing Statistician&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you look at the bottom of p. 12, you will find a random permutation test for paired data. In this test, the null hypothesis that there is no difference between the distribution of the X and the Y variable. Therefore, a bootstrap permutation test will randomly swap (with probability 0.5) the values of the X and Y variables. For the difference, this results in a change of the sign of the difference.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps this formulation is similar to the one that you are considering? If so, I think the program on p. 12 formulates the problem in a precise manner and solves it efficiently by using the bootstrap method.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Aug 2024 10:20:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-generate-all-positive-negative-permutations-of-a-one-row/m-p/939054#M6259</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2024-08-13T10:20:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate all positive/negative permutations of an a one-row matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-generate-all-positive-negative-permutations-of-a-one-row/m-p/940368#M6264</link>
      <description>Thank you for the idea of `call execute` and this example module.</description>
      <pubDate>Wed, 21 Aug 2024 18:31:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-generate-all-positive-negative-permutations-of-a-one-row/m-p/940368#M6264</guid>
      <dc:creator>schuelke_wu</dc:creator>
      <dc:date>2024-08-21T18:31:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate all positive/negative permutations of a one-row matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-generate-all-positive-negative-permutations-of-a-one-row/m-p/940369#M6265</link>
      <description>Thank you. I recognize this as a valid approach to the test as opposed to whatever was originally in the slides I inherited.</description>
      <pubDate>Wed, 21 Aug 2024 18:36:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-generate-all-positive-negative-permutations-of-a-one-row/m-p/940369#M6265</guid>
      <dc:creator>schuelke_wu</dc:creator>
      <dc:date>2024-08-21T18:36:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to generate all positive/negative permutations of an a one-row matrix</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-generate-all-positive-negative-permutations-of-a-one-row/m-p/940371#M6266</link>
      <description>Very nice example. Thank you.</description>
      <pubDate>Wed, 21 Aug 2024 18:38:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-generate-all-positive-negative-permutations-of-a-one-row/m-p/940371#M6266</guid>
      <dc:creator>schuelke_wu</dc:creator>
      <dc:date>2024-08-21T18:38:51Z</dc:date>
    </item>
  </channel>
</rss>

