<?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: Nested Loop in SAS: Issue with index values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Nested-Loop-in-SAS-Issue-with-index-values/m-p/892445#M352459</link>
    <description>&lt;P&gt;No.&lt;/P&gt;
&lt;P&gt;You seem to have confused which index variable represents the observation number (aka ROW) and which one represents the variable number (aka COLUMN).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would also be clearer to empty the array after you write it to see what you are really doing.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data floyd;
array arr[*] col1-col5;
do i=1 to 5;
	do j=1 to i;
		arr[i] = i+j; 
	end;	
	output;
  call missing(of arr[*]);
end;
drop i j;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    col1    col2    col3    col4    col5

 1       2       .       .       .       .
 2       .       4       .       .       .
 3       .       .       6       .       .
 4       .       .       .       8       .
 5       .       .       .       .      10
&lt;/PRE&gt;
&lt;P&gt;So when I=2 you write two different values into ARR[2], so only the final one, 4, remains.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It becomes clearer is you use ROW and COL as the index variable names.&lt;/P&gt;
&lt;P&gt;Now it become clearer that you wanted:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;arr[col] = row+col;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Instead of&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;arr[row] = row+col;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Try&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data floyd;
array arr[*] col1-col5;
do row=1 to 5;
	do col=1 to row;
		arr[col] = row+col; 
	end;	
	output;
end;
drop row col;
run;
proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 02 Sep 2023 17:37:10 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-09-02T17:37:10Z</dc:date>
    <item>
      <title>Nested Loop in SAS: Issue with index values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-Loop-in-SAS-Issue-with-index-values/m-p/892444#M352458</link>
      <description>&lt;P&gt;Explain why I am getting all the EVEN values when I am doing i+j as a final result in the nested loop:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data floyd;
array arr(*) col1-col5;
do i=1 to 5;
	do j=1 to i;
		arr(i) = i+j; 
	end;	
	output;
end;
drop i j;
run;
proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vijaypratap0195_0-1693674912395.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/87582i3148EED9601186FE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vijaypratap0195_0-1693674912395.png" alt="vijaypratap0195_0-1693674912395.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;As per my understanding output has to be :&lt;/P&gt;
&lt;P&gt;Expected output:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vijaypratap0195_1-1693675160236.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/87583iFF3FCC2803CF8A52/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vijaypratap0195_1-1693675160236.png" alt="vijaypratap0195_1-1693675160236.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;and so on.........&lt;/P&gt;
&lt;P&gt;Can anyone please explain.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 Sep 2023 17:19:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-Loop-in-SAS-Issue-with-index-values/m-p/892444#M352458</guid>
      <dc:creator>vijaypratap0195</dc:creator>
      <dc:date>2023-09-02T17:19:49Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Loop in SAS: Issue with index values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-Loop-in-SAS-Issue-with-index-values/m-p/892445#M352459</link>
      <description>&lt;P&gt;No.&lt;/P&gt;
&lt;P&gt;You seem to have confused which index variable represents the observation number (aka ROW) and which one represents the variable number (aka COLUMN).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would also be clearer to empty the array after you write it to see what you are really doing.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data floyd;
array arr[*] col1-col5;
do i=1 to 5;
	do j=1 to i;
		arr[i] = i+j; 
	end;	
	output;
  call missing(of arr[*]);
end;
drop i j;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs    col1    col2    col3    col4    col5

 1       2       .       .       .       .
 2       .       4       .       .       .
 3       .       .       6       .       .
 4       .       .       .       8       .
 5       .       .       .       .      10
&lt;/PRE&gt;
&lt;P&gt;So when I=2 you write two different values into ARR[2], so only the final one, 4, remains.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It becomes clearer is you use ROW and COL as the index variable names.&lt;/P&gt;
&lt;P&gt;Now it become clearer that you wanted:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;arr[col] = row+col;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Instead of&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;arr[row] = row+col;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Try&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data floyd;
array arr[*] col1-col5;
do row=1 to 5;
	do col=1 to row;
		arr[col] = row+col; 
	end;	
	output;
end;
drop row col;
run;
proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 Sep 2023 17:37:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-Loop-in-SAS-Issue-with-index-values/m-p/892445#M352459</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-02T17:37:10Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Loop in SAS: Issue with index values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-Loop-in-SAS-Issue-with-index-values/m-p/892446#M352460</link>
      <description>&lt;P&gt;Very depth explanation, Thank you.&lt;/P&gt;</description>
      <pubDate>Sat, 02 Sep 2023 17:46:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-Loop-in-SAS-Issue-with-index-values/m-p/892446#M352460</guid>
      <dc:creator>vijaypratap0195</dc:creator>
      <dc:date>2023-09-02T17:46:06Z</dc:date>
    </item>
  </channel>
</rss>

