<?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: Is it possible to use the LOC function in SAS/IML within a loop in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Is-it-possible-to-use-the-LOC-function-in-SAS-IML-within-a-loop/m-p/628387#M5010</link>
    <description>&lt;P&gt;Better post it at IML forum . &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp; is there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 set sashelp.class;
 if mod(_n_,5)=1 then group+1;
 keep group weight height;
run;

proc iml ;
use have;
read all var {weight height} into x;
read all var {group};
close;

do i=1 to max(group);
 temp='x'+left(char(i));
 call valset(temp,x[loc(group=i),]);
 print (value(temp))[label=('x'+left(char(i)))] ;
end;

quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 29 Feb 2020 11:54:34 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2020-02-29T11:54:34Z</dc:date>
    <item>
      <title>Is it possible to use the LOC function in SAS/IML within a loop</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Is-it-possible-to-use-the-LOC-function-in-SAS-IML-within-a-loop/m-p/628252#M5009</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have my data saved in an excel file, which I have imported into SAS/IML and read the data into columns.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 2 columns as shown in the file attached:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;data: 10 12 15 20 -50 50 30 15 12 16 16 20 -20 70 40 18 (16 observations)&lt;/P&gt;&lt;P&gt;blocks: 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 (2 block 1 and 2 with 8 observations in each block).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to generate separate columns for each set of data within a block. i.e I want to have the first 8 observations in an array maybe called X1, then the remaining 8 observations to be saved in another array called X2.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For data with more than 2 blocks say n, I should have X1, X2,....., Xn arrays.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;DJ&lt;/P&gt;</description>
      <pubDate>Fri, 28 Feb 2020 15:59:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Is-it-possible-to-use-the-LOC-function-in-SAS-IML-within-a-loop/m-p/628252#M5009</guid>
      <dc:creator>DJ20</dc:creator>
      <dc:date>2020-02-28T15:59:35Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to use the LOC function in SAS/IML within a loop</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Is-it-possible-to-use-the-LOC-function-in-SAS-IML-within-a-loop/m-p/628387#M5010</link>
      <description>&lt;P&gt;Better post it at IML forum . &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13684"&gt;@Rick_SAS&lt;/a&gt;&amp;nbsp; is there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 set sashelp.class;
 if mod(_n_,5)=1 then group+1;
 keep group weight height;
run;

proc iml ;
use have;
read all var {weight height} into x;
read all var {group};
close;

do i=1 to max(group);
 temp='x'+left(char(i));
 call valset(temp,x[loc(group=i),]);
 print (value(temp))[label=('x'+left(char(i)))] ;
end;

quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 29 Feb 2020 11:54:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Is-it-possible-to-use-the-LOC-function-in-SAS-IML-within-a-loop/m-p/628387#M5010</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-02-29T11:54:34Z</dc:date>
    </item>
    <item>
      <title>Re: Is it possible to use the LOC function in SAS/IML within a loop</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Is-it-possible-to-use-the-LOC-function-in-SAS-IML-within-a-loop/m-p/628402#M5011</link>
      <description>&lt;P&gt;Are you going to access all the arrays simultaneously, or do you want to process them one by one?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to process them one-by-one, then this is BY-group processing, which you can accomplish in SAS/IML by using &lt;A href="https://blogs.sas.com/content/iml/2011/11/01/the-unique-loc-trick-a-real-treat.html" target="_self"&gt;the UNIQUE-LOC technique:&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
data={ 10 12 15 20 -50 50 30 15 12 16 16 20 -20 70 40 18}`;
blocks={ 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 };

u = unique(blocks);         /* 2. Unique values (levels) of categorical variable. */
s = j(1, ncol(u));          /* 3. Allocate vector to hold results */
do i = 1 to ncol(u);        /* 4. For each level... */
   idx = loc(blocks=u[i]);  /* 5. Find observations in level */
   X = data[idx];
   /* now process these observations */
   *print (sum(x));
end;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you think you want to use separate matrices, X1, X2, ..., I advise you to rethink the problem. Although it is possible to do what you describe, in my experience (20+ years of IML programming), it is usually easier to deal with one matrix (rows of DATA, indexed by BLOCK) than to create a lot of matrices with separate names. In the recent versions of IML, you can use lists for this, but I recall from one of your previous posts that you are using an old version of SAS/IML that does not support lists.&lt;/P&gt;
&lt;P&gt;Without lists, you would need to use programming tricks that are better avoided by someone who is new to the language.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since you have posted multiple posts on the topic of designing experiments, I feel compelled to point out that SAS supports pre-written procedures to help you design experiments. For some examples, see &lt;A href="https://www.lexjansen.com/nesug/nesug05/an/an1.pdf" target="_self"&gt;Bilenas (2005)&lt;/A&gt; or &lt;A href="https://www.crcpress.com/Design-and-Analysis-of-Experiments-with-SAS/Lawson/p/book/9781420060607" target="_self"&gt;Lawson's book (2010).&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;In addition, many people find that JMP software is an excellent tool for the design and analysis of experiments.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 29 Feb 2020 11:01:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/Is-it-possible-to-use-the-LOC-function-in-SAS-IML-within-a-loop/m-p/628402#M5011</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-02-29T11:01:38Z</dc:date>
    </item>
  </channel>
</rss>

