<?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: Split one dataset into two evenly but with a catch. in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Split-one-dataset-into-two-evenly-but-with-a-catch/m-p/352035#M23223</link>
    <description>&lt;P&gt;Right! Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;.&lt;/P&gt;</description>
    <pubDate>Fri, 21 Apr 2017 04:19:33 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2017-04-21T04:19:33Z</dc:date>
    <item>
      <title>Split one dataset into two evenly but with a catch.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Split-one-dataset-into-two-evenly-but-with-a-catch/m-p/351952#M23204</link>
      <description>&lt;P&gt;I want to have&amp;nbsp;two datasets split evenly from a much larger dataset but before the split, SAS must not split obersvations that are in same zipcodes (criteria).&amp;nbsp; We want to mail an food offer&amp;nbsp;from a dataset we created&amp;nbsp;but&amp;nbsp; with two different valid dates.&amp;nbsp; The first valid date is assigned to the first splited dataset and second valid dates assigned to the second splited&amp;nbsp;dataset.&amp;nbsp;&amp;nbsp; However, we don't want to separate married couple&amp;nbsp;who want to dine together.&amp;nbsp; Our manual logic is to sort by zip codes and split the datasets evenly&amp;nbsp;and right before the split make sure no two address are the same.&amp;nbsp; Below is what our rows of data look likes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="562"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;ID&lt;/TD&gt;
&lt;TD width="115"&gt;FN&lt;/TD&gt;
&lt;TD width="64"&gt;LN&lt;/TD&gt;
&lt;TD width="143"&gt;Address&lt;/TD&gt;
&lt;TD width="74"&gt;City State&lt;/TD&gt;
&lt;TD width="38"&gt;state&lt;/TD&gt;
&lt;TD width="64"&gt;ZIP&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1111111&lt;/TD&gt;
&lt;TD&gt;Wayne&lt;/TD&gt;
&lt;TD&gt;Smith&lt;/TD&gt;
&lt;TD&gt;111 Left St&lt;/TD&gt;
&lt;TD&gt;BROOKLYN&lt;/TD&gt;
&lt;TD&gt;NY&lt;/TD&gt;
&lt;TD&gt;11234&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1111112&lt;/TD&gt;
&lt;TD&gt;Mary&lt;/TD&gt;
&lt;TD&gt;Smith&lt;/TD&gt;
&lt;TD&gt;111 left&lt;/TD&gt;
&lt;TD&gt;BROOKLYN&lt;/TD&gt;
&lt;TD&gt;NY&lt;/TD&gt;
&lt;TD&gt;11234&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A dataset with 10,000 rows split evenly:&lt;/P&gt;
&lt;P&gt;Dataset 1 = 5,000&lt;/P&gt;
&lt;P&gt;Dataset 2 = 5,000&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; But don't separate same zip codes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="562"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;&amp;nbsp;Please help!&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Thu, 20 Apr 2017 23:47:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Split-one-dataset-into-two-evenly-but-with-a-catch/m-p/351952#M23204</guid>
      <dc:creator>sdang</dc:creator>
      <dc:date>2017-04-20T23:47:01Z</dc:date>
    </item>
    <item>
      <title>Re: Split one dataset into two evenly but with a catch.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Split-one-dataset-into-two-evenly-but-with-a-catch/m-p/351963#M23207</link>
      <description>&lt;P&gt;If you're only looking for a rough split, you could just test to find the midway point, and then split the file at the first zipcode change after that.&amp;nbsp; Something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  do id=1 to 10000;
    zip=ceil(ranuni(0)*20);
    output;
  end;
run;

proc sort data=have;
  by zip;
run;


data file1 file2;
  set have nobs=n;
  by zip;

  retain mid 0;
  if _n_ &amp;gt; (n/2) and first.zip then mid=1;

  if mid=0 then output file1;
  else output file2;&lt;BR /&gt;&lt;BR /&gt;  drop mid;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Apr 2017 00:46:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Split-one-dataset-into-two-evenly-but-with-a-catch/m-p/351963#M23207</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2017-04-21T00:46:00Z</dc:date>
    </item>
    <item>
      <title>Re: Split one dataset into two evenly but with a catch.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Split-one-dataset-into-two-evenly-but-with-a-catch/m-p/351968#M23210</link>
      <description>&lt;P&gt;This might work. i have not tested code completly&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;/*gets into your half be careful here you can get decimals if count is odd*/&lt;BR /&gt;proc sql;&lt;BR /&gt;select count(*)/ 2 into :halfnum from intial_table;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;/*gets you same zipcode &amp;nbsp;be careful zipcode is not right one probably you should pick addres*/&lt;BR /&gt;proc sql;&lt;BR /&gt;create table samezipcode_firsthalf&lt;BR /&gt;select * from intial_table&lt;BR /&gt;where zipped in &lt;BR /&gt;(select zipped from&amp;nbsp;intialtable&lt;BR /&gt;group by name&lt;BR /&gt;having count(*) gt 1) ;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;/*create another table without same zipcode records as id seems unqique*/&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;create newintialtable as&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select * from intialtable where&amp;nbsp;&lt;/P&gt;
&lt;P&gt;id not in (select id from&amp;nbsp;&lt;SPAN&gt;samezipcode_firsthalf);&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/* picking up remaining records for first dataset*/&lt;BR /&gt;proc sql;&lt;BR /&gt;select count(*) into :newtot&lt;BR /&gt;from amezipcode_firsthalf;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt;insert into samezipcode_firsthalf&lt;BR /&gt;select * from&amp;nbsp;&lt;SPAN&gt;newintialtable /* pick up new records from new intial table */&lt;/SPAN&gt;&lt;BR /&gt;where monotonic() le %eval( %left(&amp;amp;halfnum)-%left(&amp;amp;newtot));&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;/* id is unique as per your data*/&lt;BR /&gt;proc sql;&lt;BR /&gt;create table second as &lt;BR /&gt;select * from intial_table&lt;BR /&gt;where id not in (select id from&amp;nbsp;&lt;SPAN&gt;samezipcode_firsthalf&lt;/SPAN&gt;);&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2017 01:37:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Split-one-dataset-into-two-evenly-but-with-a-catch/m-p/351968#M23210</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2017-04-21T01:37:58Z</dc:date>
    </item>
    <item>
      <title>Re: Split one dataset into two evenly but with a catch.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Split-one-dataset-into-two-evenly-but-with-a-catch/m-p/351973#M23213</link>
      <description>&lt;P&gt;Another way to do a rough split:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have; by zip; run;

data set1 set2;
retain set1;
set have; by zip;
if first.zip then set1 = not set1;
if set1 then output set1; else output set2;
drop set1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Apr 2017 04:18:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Split-one-dataset-into-two-evenly-but-with-a-catch/m-p/351973#M23213</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-04-21T04:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: Split one dataset into two evenly but with a catch.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Split-one-dataset-into-two-evenly-but-with-a-catch/m-p/351996#M23219</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need&amp;nbsp;&lt;/P&gt;
&lt;P&gt;retain set1; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;?&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2017 03:16:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Split-one-dataset-into-two-evenly-but-with-a-catch/m-p/351996#M23219</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-04-21T03:16:33Z</dc:date>
    </item>
    <item>
      <title>Re: Split one dataset into two evenly but with a catch.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Split-one-dataset-into-two-evenly-but-with-a-catch/m-p/352035#M23223</link>
      <description>&lt;P&gt;Right! Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2017 04:19:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Split-one-dataset-into-two-evenly-but-with-a-catch/m-p/352035#M23223</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-04-21T04:19:33Z</dc:date>
    </item>
  </channel>
</rss>

