<?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: Iterate through dataset with specific number of rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dataset-with-specific-number-of-rows/m-p/677105#M204224</link>
    <description>&lt;P&gt;Iterate through the specific rows and do what?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What should the output of this process look like?&lt;/P&gt;</description>
    <pubDate>Sun, 16 Aug 2020 21:01:17 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-08-16T21:01:17Z</dc:date>
    <item>
      <title>Iterate through dataset with specific number of rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dataset-with-specific-number-of-rows/m-p/677104#M204223</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; I'm trying to iterate through a dataset for a specific set of rows (say 5), so for the first observation when it is read it has to read through the next 4 rows. So when we read the second observation it has to loop through 3,4,5,6 rows and for third obs read through rows 4-7 &amp;amp; so on... When it comes to the bottom rows it should read what is left over. Like in row 10, it can read only 11&amp;nbsp; &amp;amp; 12.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to achieve this through retain statements or array?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the dataset might look like below:&lt;/P&gt;&lt;P&gt;DSet : A&lt;/P&gt;&lt;P&gt;ID&amp;nbsp;&amp;nbsp;&amp;nbsp; Date&amp;nbsp;&amp;nbsp;&amp;nbsp; Cost&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8/1/2020&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 100&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8/2/2020&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 230&lt;/P&gt;&lt;P&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8/3/2020&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 450&lt;/P&gt;&lt;P&gt;4&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8/4/2020&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 660&lt;/P&gt;&lt;P&gt;5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8/5/2020&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 670&lt;/P&gt;&lt;P&gt;6&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8/6/2020&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 230&lt;/P&gt;&lt;P&gt;7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8/7/2020&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 420&lt;/P&gt;&lt;P&gt;8&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8/8/2020&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 110&lt;/P&gt;&lt;P&gt;9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 8/9/2020&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 430&lt;/P&gt;&lt;P&gt;10&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;8/10/2020&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 140&lt;/P&gt;&lt;P&gt;11 &amp;nbsp;&amp;nbsp;&amp;nbsp;8/11/2020&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 180&lt;/P&gt;&lt;P&gt;12&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;8/12/2020&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 340&lt;/P&gt;</description>
      <pubDate>Sun, 16 Aug 2020 20:53:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dataset-with-specific-number-of-rows/m-p/677104#M204223</guid>
      <dc:creator>swamgan12</dc:creator>
      <dc:date>2020-08-16T20:53:57Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through dataset with specific number of rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dataset-with-specific-number-of-rows/m-p/677105#M204224</link>
      <description>&lt;P&gt;Iterate through the specific rows and do what?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What should the output of this process look like?&lt;/P&gt;</description>
      <pubDate>Sun, 16 Aug 2020 21:01:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dataset-with-specific-number-of-rows/m-p/677105#M204224</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-16T21:01:17Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through dataset with specific number of rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dataset-with-specific-number-of-rows/m-p/677106#M204225</link>
      <description>&lt;P&gt;What are you trying to do with those other row's values?&lt;/P&gt;
&lt;P&gt;Should be simple with POINT= option.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have ;
   do p=_n_+1 to min(_n_+4,nobs);
      set have point=p nobs=nobs;
      * do somthing? ;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 16 Aug 2020 21:19:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dataset-with-specific-number-of-rows/m-p/677106#M204225</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-08-16T21:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through dataset with specific number of rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dataset-with-specific-number-of-rows/m-p/677129#M204234</link>
      <description>&lt;P&gt;Or,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b;
length lastRow 8;
set a;
do lastRow = max(5, _n_) to _n_ + 4;
    output;
    end;
run;

proc sort data=b; by lastRow date; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;alternatively:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Aug 2020 02:45:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dataset-with-specific-number-of-rows/m-p/677129#M204234</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-08-17T02:45:04Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through dataset with specific number of rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dataset-with-specific-number-of-rows/m-p/677148#M204239</link>
      <description>&lt;P&gt;Sorry should have been more clear... Once I read the 5 observations have to sum up the Cost columns.. I have like 3 Cost columns, Cost1, Cost2, Cost3. Need to sum all the 3 columns across 5 observations and see which exceeds.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Aug 2020 08:32:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dataset-with-specific-number-of-rows/m-p/677148#M204239</guid>
      <dc:creator>swamgan12</dc:creator>
      <dc:date>2020-08-17T08:32:04Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through dataset with specific number of rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dataset-with-specific-number-of-rows/m-p/677159#M204242</link>
      <description>&lt;P&gt;To avoid further tinkering, please post what you expect as result from the data you have posted. And take care that the data is as close as possible to your real-world-data.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Aug 2020 08:52:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dataset-with-specific-number-of-rows/m-p/677159#M204242</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-08-17T08:52:15Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through dataset with specific number of rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dataset-with-specific-number-of-rows/m-p/677169#M204247</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/154102"&gt;@swamgan12&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Sorry should have been more clear... Once I read the 5 observations have to sum up the Cost columns.. I have like 3 Cost columns, Cost1, Cost2, Cost3. Need to sum all the 3 columns across 5 observations and see which exceeds.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;But you don't show columns COST1, COST2 and COST3 in your example data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please provide a clear explanation, &lt;STRONG&gt;which matches the data in your example&lt;/STRONG&gt;, and please show the desired output.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Aug 2020 10:40:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dataset-with-specific-number-of-rows/m-p/677169#M204247</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-17T10:40:42Z</dc:date>
    </item>
    <item>
      <title>Re: Iterate through dataset with specific number of rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dataset-with-specific-number-of-rows/m-p/677179#M204255</link>
      <description>&lt;P&gt;It is look-forward problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data a;
input ID    Date  : $20.  Cost;
cards;
1      8/1/2020       100
2      8/2/2020        230
3      8/3/2020        450
4      8/4/2020        660
5      8/5/2020        670
6      8/6/2020        230
7      8/7/2020        420
8      8/8/2020        110
9      8/9/2020        430
10    8/10/2020      140
11    8/11/2020      180
12    8/12/2020      340
;

data want;
 merge a(rename=(cost=cost1))
       a(keep=cost rename=(cost=cost2) firstobs=2)
	   a(keep=cost rename=(cost=cost3) firstobs=3)
       a(keep=cost rename=(cost=cost4) firstobs=4)
       a(keep=cost rename=(cost=cost5) firstobs=5);
sum=sum(of cost1-cost5);
run;
&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Aug 2020 12:03:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Iterate-through-dataset-with-specific-number-of-rows/m-p/677179#M204255</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-08-17T12:03:03Z</dc:date>
    </item>
  </channel>
</rss>

