<?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: Create datasets in batches of 10 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-datasets-in-batches-of-10/m-p/674222#M202996</link>
    <description>Why does the title say "batches of 10" and the question discusses "5 records"</description>
    <pubDate>Mon, 03 Aug 2020 23:06:08 GMT</pubDate>
    <dc:creator>RichardDeVen</dc:creator>
    <dc:date>2020-08-03T23:06:08Z</dc:date>
    <item>
      <title>Create datasets in batches of 10</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-datasets-in-batches-of-10/m-p/674192#M202975</link>
      <description>&lt;P&gt;Hi All&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with many records. I want to assign the same batch number to the first 5 records and add 1 to the batch number for the next 5 records and so on. But if the ID after the 5th record is the same as the 5th record's ID then put the 6th record in the same batch as the 5th record. In this example: 1 AA , 2 BB, 3CC, 4 EE and 4AE should be in the same batch 001. However, the 6th record has the same ID as the last record of the first batch hence it also falls into 001.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please see below example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID Name Batch&lt;/P&gt;&lt;P&gt;1&amp;nbsp; AA&amp;nbsp; 001&lt;/P&gt;&lt;P&gt;2&amp;nbsp; BB&amp;nbsp; 001&lt;/P&gt;&lt;P&gt;3&amp;nbsp; CC 001&lt;/P&gt;&lt;P&gt;4&amp;nbsp; EE 001&lt;/P&gt;&lt;P&gt;4&amp;nbsp; AE 001&lt;/P&gt;&lt;P&gt;4&amp;nbsp; BE 001&lt;/P&gt;&lt;P&gt;5&amp;nbsp; FF 002&lt;/P&gt;&lt;P&gt;5&amp;nbsp; FF 002&lt;/P&gt;&lt;P&gt;7 GG 002&amp;nbsp;&lt;/P&gt;&lt;P&gt;8 HH 002&lt;/P&gt;&lt;P&gt;9&amp;nbsp; II&amp;nbsp; &amp;nbsp;002&lt;/P&gt;&lt;P&gt;22 JJ 003&lt;/P&gt;&lt;P&gt;23 KK 003&lt;/P&gt;&lt;P&gt;24 MM 003&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help will really be appreciated.&lt;/P&gt;</description>
      <pubDate>Mon, 03 Aug 2020 18:58:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-datasets-in-batches-of-10/m-p/674192#M202975</guid>
      <dc:creator>lsehlola</dc:creator>
      <dc:date>2020-08-03T18:58:31Z</dc:date>
    </item>
    <item>
      <title>Re: Create datasets in batches of 10</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-datasets-in-batches-of-10/m-p/674193#M202976</link>
      <description>&lt;P&gt;What if the above rules require 7 with the same batch?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If we put 6 in the first batch, do we put 4 in the second batch?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Aug 2020 19:04:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-datasets-in-batches-of-10/m-p/674193#M202976</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-03T19:04:54Z</dc:date>
    </item>
    <item>
      <title>Re: Create datasets in batches of 10</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-datasets-in-batches-of-10/m-p/674199#M202981</link>
      <description>What if the above rules require 7 with the same batch?&lt;BR /&gt;&lt;BR /&gt;Then ID - 5 will be in the same batch 001. Meaning you take 8 records instead of 7.&lt;BR /&gt;&lt;BR /&gt;If we put 6 in the first batch, do we put 4 in the second batch?&lt;BR /&gt;You put 5 in the next batch unless the 6th ID is the same as the 5th ID</description>
      <pubDate>Mon, 03 Aug 2020 19:28:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-datasets-in-batches-of-10/m-p/674199#M202981</guid>
      <dc:creator>lsehlola</dc:creator>
      <dc:date>2020-08-03T19:28:41Z</dc:date>
    </item>
    <item>
      <title>Re: Create datasets in batches of 10</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-datasets-in-batches-of-10/m-p/674204#M202985</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
	retain batch 1;
	prev_id=lag(id);
	number_in_id+1;
	if number_in_id&amp;gt;=5 and id^=prev_id then do;
	    batch+1;
		number_in_id=0;
	end;
	drop prev_id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 03 Aug 2020 20:09:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-datasets-in-batches-of-10/m-p/674204#M202985</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-08-03T20:09:12Z</dc:date>
    </item>
    <item>
      <title>Re: Create datasets in batches of 10</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-datasets-in-batches-of-10/m-p/674221#M202995</link>
      <description>&lt;P&gt;A DOW loop whose embedded &lt;CODE&gt;SET&lt;/CODE&gt;&amp;nbsp;has by-groups processed using the &lt;CODE&gt;NOTSORTED&lt;/CODE&gt; option of the &lt;CODE&gt;BY&lt;/CODE&gt; statement will respond to the end of a contiguous block of values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;data want;
  retain batch_num 1;

  /* batch_num # is applied to 5 rows at a time,
   * extended for each row of final id in the batch
   */

  do _n_ = 1 by 1 until (_n_ &amp;gt;= 5 and last.id);     
    set have;
    by id NOTSORTED;
    OUTPUT;
  end;
  batch_num + 1;
run;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2020 02:29:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-datasets-in-batches-of-10/m-p/674221#M202995</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-08-04T02:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: Create datasets in batches of 10</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-datasets-in-batches-of-10/m-p/674222#M202996</link>
      <description>Why does the title say "batches of 10" and the question discusses "5 records"</description>
      <pubDate>Mon, 03 Aug 2020 23:06:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-datasets-in-batches-of-10/m-p/674222#M202996</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-08-03T23:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: Create datasets in batches of 10</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-datasets-in-batches-of-10/m-p/674241#M203001</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12477"&gt;@RichardDeVen&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think you want&lt;/P&gt;
&lt;P&gt;&amp;nbsp; ... "until (_n_ &lt;EM&gt;&lt;STRONG&gt;&amp;gt;=&lt;/STRONG&gt;&lt;/EM&gt; 5 and last.id)"&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2020 01:38:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-datasets-in-batches-of-10/m-p/674241#M203001</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-08-04T01:38:11Z</dc:date>
    </item>
    <item>
      <title>Re: Create datasets in batches of 10</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-datasets-in-batches-of-10/m-p/674250#M203006</link>
      <description>Indeed!</description>
      <pubDate>Tue, 04 Aug 2020 02:26:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-datasets-in-batches-of-10/m-p/674250#M203006</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-08-04T02:26:01Z</dc:date>
    </item>
    <item>
      <title>Re: Create datasets in batches of 10</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-datasets-in-batches-of-10/m-p/674330#M203045</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Name $;
cards;
1  AA
2  BB
3  CC
4  EE
4  AE
4  BE
5  FF
5  FF
7  GG 
8  HH 
9  II
22 JJ
23 KK
24 MM
;

data want;
 set have;
 retain batch 1;
 n+1;
 if n&amp;gt;5 and id ne lag(id) then do;batch+1;n=1;end;
 drop n;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;BTW, I like this kind of Q .&lt;/P&gt;</description>
      <pubDate>Tue, 04 Aug 2020 12:25:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-datasets-in-batches-of-10/m-p/674330#M203045</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-08-04T12:25:40Z</dc:date>
    </item>
  </channel>
</rss>

