<?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 Use SAS do loop and array to create a dataset in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Use-SAS-do-loop-and-array-to-create-a-dataset/m-p/852979#M337171</link>
    <description>&lt;P&gt;I am trying to create a SAS dataset that looks like the following &lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2023-01-09 at 8.42.25 PM.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/79208iB305FB1445E5EE10/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2023-01-09 at 8.42.25 PM.png" alt="Screenshot 2023-01-09 at 8.42.25 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I am attempting to use array and a do loop to accomplish this via the following code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DATA dat;
    array new(20) X1-X20;
    Do i = 1 to 20;
    	new[i] = new[i] + 1;
    	output;
    end;
RUN;&lt;/PRE&gt;&lt;P&gt;This code gets me close to the desired dataframe. That is, the position of the missing values are correct however it populates the dataset with all 1s (see below for output). I am not sure what I am doing wrong. I don't understand why new[i[ = new[i] + 1 doesn't increment.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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="Screenshot 2023-01-09 at 8.41.23 PM.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/79209i2B7E89FBF0BED1C1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2023-01-09 at 8.41.23 PM.png" alt="Screenshot 2023-01-09 at 8.41.23 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description>
    <pubDate>Tue, 10 Jan 2023 01:45:58 GMT</pubDate>
    <dc:creator>stat34986</dc:creator>
    <dc:date>2023-01-10T01:45:58Z</dc:date>
    <item>
      <title>Use SAS do loop and array to create a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-SAS-do-loop-and-array-to-create-a-dataset/m-p/852979#M337171</link>
      <description>&lt;P&gt;I am trying to create a SAS dataset that looks like the following &lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2023-01-09 at 8.42.25 PM.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/79208iB305FB1445E5EE10/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2023-01-09 at 8.42.25 PM.png" alt="Screenshot 2023-01-09 at 8.42.25 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I am attempting to use array and a do loop to accomplish this via the following code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;DATA dat;
    array new(20) X1-X20;
    Do i = 1 to 20;
    	new[i] = new[i] + 1;
    	output;
    end;
RUN;&lt;/PRE&gt;&lt;P&gt;This code gets me close to the desired dataframe. That is, the position of the missing values are correct however it populates the dataset with all 1s (see below for output). I am not sure what I am doing wrong. I don't understand why new[i[ = new[i] + 1 doesn't increment.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&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="Screenshot 2023-01-09 at 8.41.23 PM.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/79209i2B7E89FBF0BED1C1/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Screenshot 2023-01-09 at 8.41.23 PM.png" alt="Screenshot 2023-01-09 at 8.41.23 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2023 01:45:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-SAS-do-loop-and-array-to-create-a-dataset/m-p/852979#M337171</guid>
      <dc:creator>stat34986</dc:creator>
      <dc:date>2023-01-10T01:45:58Z</dc:date>
    </item>
    <item>
      <title>Re: Use SAS do loop and array to create a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-SAS-do-loop-and-array-to-create-a-dataset/m-p/852982#M337173</link>
      <description>&lt;P&gt;Below should return what you're after.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dat;
  array new(20) x1-x20;
  do i = 1 to dim(new);
    do k=1 to i;
      new[k]=sum(new[k],1);
    end;
    output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Jan 2023 02:51:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-SAS-do-loop-and-array-to-create-a-dataset/m-p/852982#M337173</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-01-10T02:51:35Z</dc:date>
    </item>
    <item>
      <title>Re: Use SAS do loop and array to create a dataset</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Use-SAS-do-loop-and-array-to-create-a-dataset/m-p/853046#M337186</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*It is IML thing.*/
proc iml;
have=t(1:20);
want=lag(have,0:19);
create want from want[c=('x1':'x20')];
append from want;
close;
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-1673351004389.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/79224i10D6350A8C029000/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ksharp_0-1673351004389.png" alt="Ksharp_0-1673351004389.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jan 2023 11:43:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Use-SAS-do-loop-and-array-to-create-a-dataset/m-p/853046#M337186</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-01-10T11:43:54Z</dc:date>
    </item>
  </channel>
</rss>

