<?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: unresolved loops in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/unresolved-loops/m-p/947726#M6322</link>
    <description>&lt;P&gt;I want the code to work for any data set, when I talked about the first 3 items, is to break the code down so it is easy for me to&amp;nbsp; check the code by hand. I am working on having a general statement. If I can get it work for these items then I can extend it to all items.&lt;/P&gt;</description>
    <pubDate>Wed, 16 Oct 2024 18:11:53 GMT</pubDate>
    <dc:creator>Salah</dc:creator>
    <dc:date>2024-10-16T18:11:53Z</dc:date>
    <item>
      <title>unresolved loops</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/unresolved-loops/m-p/947711#M6316</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;If I have one if statement then the code works ok however, the result is wrong, If I added the two if statements, then the code goes into indefinite mode and I had to terminate the SAS.&amp;nbsp; My real life data is not big just 24 observations, I also tried to take 5 observations instead of the 24 but still the answer would be wrong.&lt;/P&gt;&lt;P&gt;I would appreciate any suggestions.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc iml;

X={0.2, 0.3, 0.5, 0.5, 0.5, 0.5, 0.6, 0.6, 0.7, 0.7, 0.7, 0.8, 0.8, 1.0, 1.0, 1.0, 1.0, 1.1, 1.3, 1.5, 1.5,
1.5, 1.5, 2.0, 2.0, 2.2, 2.5, 3.0, 3.0, 3.3, 3.3, 4.0, 4.0, 4.5, 4.7, 5.0, 5.4, 5.4, 7.0, 7.5, 8.8, 9.0,
10.3, 22.0, 24.5};

Y=1/sqrt(X);


Call Sort(Y);

n=nrow(Y);
m=2;
sum=0;
do i=1 to n;
	  *if (i&amp;lt;=m) then i=m+1;  if (i&amp;lt;=m) then Y[i-m]=Y[1];
	 if i &amp;gt;= n-m  then Y[i+m]=Y[n];
	*sum = sum + 1/(Y1[i+m]-Y1[i-m]);

	XXX = Y1[i+m]-Y1[i-m]; print XXX;
end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 16 Oct 2024 16:50:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/unresolved-loops/m-p/947711#M6316</guid>
      <dc:creator>Salah</dc:creator>
      <dc:date>2024-10-16T16:50:03Z</dc:date>
    </item>
    <item>
      <title>Re: unresolved loops</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/unresolved-loops/m-p/947715#M6317</link>
      <description>&lt;P&gt;Inside the loop is the statement:&lt;BR /&gt;&lt;STRONG&gt;if (i&amp;lt;=m) then Y[i-m]=Y[1];&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;When i=1 and m=2, the expression i-m= -1. The vectors in IML are one-based arrays, so it is an error to try to set Y[-1]. Thus, the program gives the error&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;ERROR: (execution) Invalid subscript or subscript out of range.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW, later, the program tries to assign XXX = Y1[i+m]-Y1[i-m]; There is no Y1 array, so perhaps you mean to use Y.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2024 17:15:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/unresolved-loops/m-p/947715#M6317</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2024-10-16T17:15:01Z</dc:date>
    </item>
    <item>
      <title>Re: unresolved loops</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/unresolved-loops/m-p/947718#M6318</link>
      <description>&lt;P&gt;thank you for the reply, yes, when&amp;nbsp;&lt;SPAN&gt;i-m= -1 that is why I used the if statement so i=m+1 and eventually the first 3 terms will be Y3-Y1, Y4-Y1, Y5-Y1.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;And you are right, I mean Y not Y1. I just copied the old code and forgot to fix it.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2024 17:31:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/unresolved-loops/m-p/947718#M6318</guid>
      <dc:creator>Salah</dc:creator>
      <dc:date>2024-10-16T17:31:41Z</dc:date>
    </item>
    <item>
      <title>Re: unresolved loops</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/unresolved-loops/m-p/947721#M6319</link>
      <description>&lt;P&gt;To make sure we are talking about the same statements, I want to emphasize that the first comment in the loop applies only up to the first semicolon, NOT the end of the line. So the program that is being run is&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do i=1 to n;
   if (i&amp;lt;=m) then Y[i-m]=Y[1];
   if i &amp;gt;= n-m  then Y[i+m]=Y[n];
   XXX = Y1[i+m]-Y1[i-m]; 
   print XXX;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The first statement inside the loop is invalid.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2024 17:56:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/unresolved-loops/m-p/947721#M6319</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2024-10-16T17:56:21Z</dc:date>
    </item>
    <item>
      <title>Re: unresolved loops</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/unresolved-loops/m-p/947723#M6320</link>
      <description>&lt;P&gt;I understand, but how would I fix it ?&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2024 17:58:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/unresolved-loops/m-p/947723#M6320</guid>
      <dc:creator>Salah</dc:creator>
      <dc:date>2024-10-16T17:58:19Z</dc:date>
    </item>
    <item>
      <title>Re: unresolved loops</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/unresolved-loops/m-p/947724#M6321</link>
      <description>&lt;P&gt;If you want "&lt;SPAN&gt;the first 3 terms to be Y3-Y1, Y4-Y1, Y5-Y1" then use&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Y[1:3] = Y[3:5] - Y[1];&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2024 18:07:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/unresolved-loops/m-p/947724#M6321</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2024-10-16T18:07:00Z</dc:date>
    </item>
    <item>
      <title>Re: unresolved loops</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/unresolved-loops/m-p/947726#M6322</link>
      <description>&lt;P&gt;I want the code to work for any data set, when I talked about the first 3 items, is to break the code down so it is easy for me to&amp;nbsp; check the code by hand. I am working on having a general statement. If I can get it work for these items then I can extend it to all items.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2024 18:11:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/unresolved-loops/m-p/947726#M6322</guid>
      <dc:creator>Salah</dc:creator>
      <dc:date>2024-10-16T18:11:53Z</dc:date>
    </item>
    <item>
      <title>Re: unresolved loops</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/unresolved-loops/m-p/947734#M6323</link>
      <description>&lt;P&gt;I am sorry, but I do not understand the general algorithm that you want to apply. If you want to use the value m to determine the number of elements to copy, then perhaps the following statements will help:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* subtract Y[1] from elements m+1,m+2,...,2*m+1 and copy those 
values into elements 1,2,...,m+1 */
Y1 = y[1];
idx = 1:(1+m);
Y[idx] = Y[m+idx] - Y1;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If that is not what you want, please explain and provide an example.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2024 18:44:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/unresolved-loops/m-p/947734#M6323</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2024-10-16T18:44:04Z</dc:date>
    </item>
  </channel>
</rss>

