<?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: how to make a loop to duplicate previous rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-make-a-loop-to-duplicate-previous-rows/m-p/471294#M120693</link>
    <description>&lt;P&gt;Whats the logic? You can control the output of a line using the OUTPUT statement, but it depends on the logic.&lt;/P&gt;
&lt;P&gt;For example, this outputs the first two rows of the sashelp.class data set the number of times&amp;nbsp;of the variable age.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set sashelp.class (obs=2);

do i=1 to age;
      output;
end;

drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/216343"&gt;@Howiewang&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am a new SAS user , firstly forgive me for my poor English grammar please, then the following is my problem.&lt;/P&gt;
&lt;P&gt;I want to write a loop to make the table like that:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;have:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;id name&lt;/P&gt;
&lt;P&gt;1 Jam&lt;/P&gt;
&lt;P&gt;2 John&lt;/P&gt;
&lt;P&gt;3 Will&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;newid id name&lt;/P&gt;
&lt;P&gt;1 1 Jam&lt;/P&gt;
&lt;P&gt;2 1 Jam&lt;/P&gt;
&lt;P&gt;3 2 John&lt;/P&gt;
&lt;P&gt;4 1 Jam&lt;/P&gt;
&lt;P&gt;5 2 John&lt;/P&gt;
&lt;P&gt;6 3 Will&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 19 Jun 2018 03:59:40 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-06-19T03:59:40Z</dc:date>
    <item>
      <title>how to make a loop to duplicate previous rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-make-a-loop-to-duplicate-previous-rows/m-p/471287#M120689</link>
      <description>&lt;P&gt;I am a new SAS user , firstly forgive me for my poor English grammar please, then the following is my problem.&lt;/P&gt;&lt;P&gt;I want to write a loop to make the table like that:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;have:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id name&lt;/P&gt;&lt;P&gt;1 Jam&lt;/P&gt;&lt;P&gt;2 John&lt;/P&gt;&lt;P&gt;3 Will&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;want:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;newid id name&lt;/P&gt;&lt;P&gt;1 1 Jam&lt;/P&gt;&lt;P&gt;2 1 Jam&lt;/P&gt;&lt;P&gt;3 2 John&lt;/P&gt;&lt;P&gt;4 1 Jam&lt;/P&gt;&lt;P&gt;5 2 John&lt;/P&gt;&lt;P&gt;6 3 Will&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;P.S. the logic should be following:&lt;/P&gt;&lt;P&gt;the logic should be when i have N row in raw table;&lt;/P&gt;&lt;P&gt;when I try to create new table, then i write the first row like the first row of raw table;&amp;nbsp;&lt;/P&gt;&lt;P&gt;then i try to create second step that copy first row and second rows of raw table and they should be second and third rows in new table;&lt;/P&gt;&lt;P&gt;then when i create third step that copy first,second and third rows of raw table and&amp;nbsp; they shoud be forth,fifth and sixth rows in new table;&lt;/P&gt;&lt;P&gt;etc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the Nth step should be that copy first row to Nth rows of raw table, then the whole number of rows should be (1+N)*(N/2), the first row of raw table is copied in N times and second one should be (N-1) times;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jun 2018 06:09:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-make-a-loop-to-duplicate-previous-rows/m-p/471287#M120689</guid>
      <dc:creator>Howiewang</dc:creator>
      <dc:date>2018-06-19T06:09:11Z</dc:date>
    </item>
    <item>
      <title>Re: how to make a loop to duplicate previous rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-make-a-loop-to-duplicate-previous-rows/m-p/471293#M120692</link>
      <description>&lt;P&gt;Reading the input only once:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id name $;
datalines;
1 Jam
2 John
3 Will
;

data want;
set have nobs=nobs;
do i = _n_ to nobs;
    newId = (i * i-1)/2 + _n_;
    output;
    end;
drop i;
run;

proc sort data=want; by newId; run;

proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 19 Jun 2018 03:57:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-make-a-loop-to-duplicate-previous-rows/m-p/471293#M120692</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-06-19T03:57:36Z</dc:date>
    </item>
    <item>
      <title>Re: how to make a loop to duplicate previous rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-make-a-loop-to-duplicate-previous-rows/m-p/471294#M120693</link>
      <description>&lt;P&gt;Whats the logic? You can control the output of a line using the OUTPUT statement, but it depends on the logic.&lt;/P&gt;
&lt;P&gt;For example, this outputs the first two rows of the sashelp.class data set the number of times&amp;nbsp;of the variable age.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set sashelp.class (obs=2);

do i=1 to age;
      output;
end;

drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/216343"&gt;@Howiewang&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I am a new SAS user , firstly forgive me for my poor English grammar please, then the following is my problem.&lt;/P&gt;
&lt;P&gt;I want to write a loop to make the table like that:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;have:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;id name&lt;/P&gt;
&lt;P&gt;1 Jam&lt;/P&gt;
&lt;P&gt;2 John&lt;/P&gt;
&lt;P&gt;3 Will&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;newid id name&lt;/P&gt;
&lt;P&gt;1 1 Jam&lt;/P&gt;
&lt;P&gt;2 1 Jam&lt;/P&gt;
&lt;P&gt;3 2 John&lt;/P&gt;
&lt;P&gt;4 1 Jam&lt;/P&gt;
&lt;P&gt;5 2 John&lt;/P&gt;
&lt;P&gt;6 3 Will&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jun 2018 03:59:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-make-a-loop-to-duplicate-previous-rows/m-p/471294#M120693</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-19T03:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: how to make a loop to duplicate previous rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-make-a-loop-to-duplicate-previous-rows/m-p/471309#M120704</link>
      <description>&lt;P&gt;the logic should be when i have N row in raw table;&lt;/P&gt;&lt;P&gt;when I try to create new table, then i write the first row like the first row of raw table;&amp;nbsp;&lt;/P&gt;&lt;P&gt;then i try to create second step that copy first row and second rows of raw table and they should be second and third rows in new table;&lt;/P&gt;&lt;P&gt;then when i create third step that copy first,second and third rows of raw table and&amp;nbsp; they shoud be forth,fifth and sixth rows in new table;&lt;/P&gt;&lt;P&gt;etc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the Nth step should be that copy first row to Nth rows of raw table, then the whole number of rows should be (1+N)*(N/2), the first row of raw table is copied in N times and second one should be (N-1) times;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;that's the logic what i want,&lt;/P&gt;&lt;P&gt;thank for your patience to read this description.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jun 2018 06:07:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-make-a-loop-to-duplicate-previous-rows/m-p/471309#M120704</guid>
      <dc:creator>Howiewang</dc:creator>
      <dc:date>2018-06-19T06:07:00Z</dc:date>
    </item>
  </channel>
</rss>

