<?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 split a data based on different value in a variable. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/split-a-data-based-on-different-value-in-a-variable/m-p/497771#M132063</link>
    <description>&lt;P&gt;dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how can I split a&amp;nbsp;&amp;nbsp;data based on the different values in a variable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for example, I have a data&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;person_ctry_code, company_name
US,A
UK,B
GB,C
NZ,D&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;how could&amp;nbsp;I split it into&amp;nbsp;three datasets? one is&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;person_ctry_code, company_name
US,A&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;, second is&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;person_ctry_code, company_name
GB,B
GB,C&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;third is,&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;person_ctry_code, company_name
NZ,D&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks in advance.&lt;/P&gt;</description>
    <pubDate>Fri, 21 Sep 2018 11:53:28 GMT</pubDate>
    <dc:creator>France</dc:creator>
    <dc:date>2018-09-21T11:53:28Z</dc:date>
    <item>
      <title>split a data based on different value in a variable.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/split-a-data-based-on-different-value-in-a-variable/m-p/497771#M132063</link>
      <description>&lt;P&gt;dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how can I split a&amp;nbsp;&amp;nbsp;data based on the different values in a variable?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for example, I have a data&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;person_ctry_code, company_name
US,A
UK,B
GB,C
NZ,D&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;how could&amp;nbsp;I split it into&amp;nbsp;three datasets? one is&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;person_ctry_code, company_name
US,A&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;, second is&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;person_ctry_code, company_name
GB,B
GB,C&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;third is,&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;person_ctry_code, company_name
NZ,D&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks in advance.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Sep 2018 11:53:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/split-a-data-based-on-different-value-in-a-variable/m-p/497771#M132063</guid>
      <dc:creator>France</dc:creator>
      <dc:date>2018-09-21T11:53:28Z</dc:date>
    </item>
    <item>
      <title>Re: split a data based on different value in a variable.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/split-a-data-based-on-different-value-in-a-variable/m-p/497784#M132072</link>
      <description>&lt;P&gt;You would not want to.&amp;nbsp; This would mean 3 * storage needs (e.g. 3 * header blocks, 3 * read, 3 * write etc.), not to mention you would then need masses of complicated messy code which will fall over each time.&amp;nbsp; Never split data up unless there is an extremely good reason (i.e. if there is a restriction on the recipient end, or data is huge &amp;gt; tb).&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As for how, you would:&lt;/P&gt;
&lt;PRE&gt;proc sort data=have out=loop nodupkey;
  by company_name;
run;
data _null_:
  set loop;
  call execute(cat('data ',strip(company_name),'; set have; where company_name="',strip(company_name),'"; run;'));
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Sep 2018 12:12:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/split-a-data-based-on-different-value-in-a-variable/m-p/497784#M132072</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-21T12:12:09Z</dc:date>
    </item>
    <item>
      <title>Re: split a data based on different value in a variable.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/split-a-data-based-on-different-value-in-a-variable/m-p/497786#M132073</link>
      <description>&lt;P&gt;First: Don't do this. Usually it is a bad idea to split up a data set like this. Use By Group processing instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Secondly, there are several ways to do this. Here is a hash object approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input person_ctry_code $ company_name $;
infile datalines dlm=",";
datalines;
US,A
GB,B
GB,C
NZ,D
;

proc sort data = have out=SortHave;
   by person_ctry_code;
run;
 
data _null_;
   if _n_=1 then do;
      if 0 then set SortHave;
      declare hash h(dataset:"SortHave(obs=0)", multidata:'y');
      h.definekey(all:'y');
      h.definedata(all:'y');
      h.definedone();
   end;
   do until(last.person_ctry_code);                                     
      set SortHave;
      by person_ctry_code;
      h.add();
   end;
   h.output(dataset:person_ctry_code);
   h.clear();
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 Sep 2018 12:16:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/split-a-data-based-on-different-value-in-a-variable/m-p/497786#M132073</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-09-21T12:16:54Z</dc:date>
    </item>
  </channel>
</rss>

