<?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: Problem with Arrays in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-Arrays/m-p/483773#M286981</link>
    <description>&lt;P&gt;Though your idea is fine, i think you can do it simpler like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=idx);
   set Ranking;
   array L{8} $;
   idx=whichc("", of L[*]);
   L[idx]=Name;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 03 Aug 2018 13:48:34 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2018-08-03T13:48:34Z</dc:date>
    <item>
      <title>Problem with Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-Arrays/m-p/483768#M286980</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the below data set. My objective to let the Name be the last variables in every row without changing the last variables. the new data set should have James as value of L6 in row 1, Lemar as value for L8 in row 2 and Thomas as value for L7 in row 3 as the arrows indicate. The data step which creates this is in step 1 below. The code I have written is titled step 2. The error message I get follows after the codes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture1.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/22199i59D2F6DBA6ABB13E/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture1.PNG" alt="Capture1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;step 1:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data Ranking;
 INFILE DATALINES DLM=',' missover;
 length CustID Name $10 L1 $20 L2 $20 L3 $20 L4 $20 L5 $20 L6 $20 L7 $20 L8 $20;
 input CustID Name $ L1 $ L2 $ L3 $ L4 $ L5 $ L6 $  L7 $ L8 $;
 cards;
 1,James,CEO,Department Head,Senior Manager,Manager, Senior Analyst, , ,
 2,Lemar,Major,Vice President, CEO, Department Head, Senior Manager,Manager,Senior Analyst, 
 3,Thomas,Technical Chief, CEO, Department Head, Senior Manager, Manager, Senior Analyst,
 ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Step 2:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data new;
    set ranking;
    array L{8} $;
    do i=8 to 1 by -1;
       if missing(L{i} ) then do;
       	  L{i+1} = Name;
       	  call missing(L{i});
       	  leave;
       end;
    end;
 run;&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;error message:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture2.PNG" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/22202i859CA04FA4D672F9/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture2.PNG" alt="Capture2.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 13:33:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-Arrays/m-p/483768#M286980</guid>
      <dc:creator>frupaul</dc:creator>
      <dc:date>2018-08-03T13:33:38Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-Arrays/m-p/483773#M286981</link>
      <description>&lt;P&gt;Though your idea is fine, i think you can do it simpler like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=idx);
   set Ranking;
   array L{8} $;
   idx=whichc("", of L[*]);
   L[idx]=Name;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Aug 2018 13:48:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-Arrays/m-p/483773#M286981</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-08-03T13:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-Arrays/m-p/483774#M286982</link>
      <description>&lt;P&gt;something like this should work. when&amp;nbsp;L&amp;nbsp; = 8&amp;nbsp; then your L&lt;SPAN class="token punctuation"&gt;&lt;FONT color="#999999"&gt;{&lt;/FONT&gt;&lt;/SPAN&gt;i&lt;SPAN class="token operator"&gt;&lt;FONT color="#a67f59"&gt;+&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;&lt;STRONG&gt;&lt;FONT color="#008080"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;&lt;FONT color="#999999"&gt;}&lt;/FONT&gt;&lt;/SPAN&gt; will become 9 and you do not have 9 elements &amp;nbsp;hence the error array&lt;/P&gt;
&lt;P&gt;subscript out of range.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data new;
    set ranking;
    array L{8} $;
    do i=1 to 8;
       if missing(L{i} ) then do;
       	  L{i} = Name;
       	  leave;
       end;
    end;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Aug 2018 13:46:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-Arrays/m-p/483774#M286982</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-08-03T13:46:46Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with Arrays</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-Arrays/m-p/483775#M286983</link>
      <description>&lt;P&gt;You loop from 8 to 1, but use i+1 in the loop, so it tries to access element 9 in the first iteration which does not exist. That is a conceptual mistake.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 13:48:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-Arrays/m-p/483775#M286983</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-08-03T13:48:52Z</dc:date>
    </item>
  </channel>
</rss>

