<?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: Splitting a file in to three based on record for particular key in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-file-in-to-three-based-on-record-for-particular-key/m-p/368097#M87748</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input value$ key;
datalines;
abc    1
bed    2
daf    1
trewr  1
fdsfds 1
fdsfsd 2
eqre   2
fdsfds 3
dsfds  3
;

proc sort data = have;
   by key;
run;

proc freq data = have noprint;
   tables key / nocum out = freqtable(drop = percent);
run;

data one twothree fourmore;
   merge have freqtable;
   by key;
   if count = 1 then output one;
   else if count in (2,3) then output twothree;
   else output fourmore; 
   drop count;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 18 Jun 2017 18:08:00 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2017-06-18T18:08:00Z</dc:date>
    <item>
      <title>Splitting a file in to three based on record for particular key</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-file-in-to-three-based-on-record-for-particular-key/m-p/368090#M87742</link>
      <description>&lt;P&gt;HI All&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Need some help in particular requirement, I am very new SAS user.&lt;/P&gt;&lt;P&gt;I have data like this&lt;/P&gt;&lt;P&gt;value &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;key&lt;/P&gt;&lt;P&gt;abc &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;bed &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;daf &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;trewr &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;fdsfds &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;fdsfsd &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;eqre &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;fdsfds &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;P&gt;dsfds &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to split the file into 3 files- &amp;nbsp;if the key has more or equal to 4 rows then one file, if the key has 2-3 rows then one file, if key has less than 2 rows then another file.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Key values can be anything. I want to know how can I count the rows for each unique value of the key field and split the file.&lt;/P&gt;</description>
      <pubDate>Sun, 18 Jun 2017 17:11:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-file-in-to-three-based-on-record-for-particular-key/m-p/368090#M87742</guid>
      <dc:creator>MB123</dc:creator>
      <dc:date>2017-06-18T17:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a file in to three based on record for particular key</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-file-in-to-three-based-on-record-for-particular-key/m-p/368092#M87744</link>
      <description>&lt;P&gt;something like this in proc sql&lt;/P&gt;
&lt;PRE&gt;proc sql;
create table want1 as
select * from have
group by key
having count(Key) ge 4;
create table want2 as
select * from have
group by key
having count(Key) between 2 and 3;
create table want3 as
select * from have
group by key
having count(Key) =  1  ;
quit;&lt;/PRE&gt;</description>
      <pubDate>Sun, 18 Jun 2017 17:29:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-file-in-to-three-based-on-record-for-particular-key/m-p/368092#M87744</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2017-06-18T17:29:35Z</dc:date>
    </item>
    <item>
      <title>Re: Splitting a file in to three based on record for particular key</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Splitting-a-file-in-to-three-based-on-record-for-particular-key/m-p/368097#M87748</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input value$ key;
datalines;
abc    1
bed    2
daf    1
trewr  1
fdsfds 1
fdsfsd 2
eqre   2
fdsfds 3
dsfds  3
;

proc sort data = have;
   by key;
run;

proc freq data = have noprint;
   tables key / nocum out = freqtable(drop = percent);
run;

data one twothree fourmore;
   merge have freqtable;
   by key;
   if count = 1 then output one;
   else if count in (2,3) then output twothree;
   else output fourmore; 
   drop count;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 18 Jun 2017 18:08:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Splitting-a-file-in-to-three-based-on-record-for-particular-key/m-p/368097#M87748</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-06-18T18:08:00Z</dc:date>
    </item>
  </channel>
</rss>

