<?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: is there anyway if i can only split datasets into different folders based on conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/is-there-anyway-if-i-can-only-split-datasets-into-different/m-p/508651#M136638</link>
    <description>&lt;P&gt;You can split your data within one step per dataset:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro split(memname);
    data sa.&amp;amp;memname
           s1a.&amp;amp;memname
           s2a.&amp;amp;memname
     ;
      set work.&amp;amp;memname;
          if folder = '19A' then output sa.&amp;amp;memname; else
          if folder = '10A' then output s1a.&amp;amp;memname; else
          if folder = '12A' then output s2a.&amp;amp;memname;
          else delete;
   run;
%mend split;
%split(&amp;lt;mem1&amp;gt;);
%split(&amp;lt;mem2&amp;gt;);
...    &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;thus will save I/O - each observation you'll read only once and write it to output.&lt;/P&gt;</description>
    <pubDate>Tue, 30 Oct 2018 12:24:53 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2018-10-30T12:24:53Z</dc:date>
    <item>
      <title>is there anyway if i can only split datasets into different folders based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/is-there-anyway-if-i-can-only-split-datasets-into-different/m-p/508599#M136612</link>
      <description>&lt;P&gt;I have few datasets and i am splitting them to different folders based on conditions. The problem is if there is one folder where there is no condition satisfied then it just creates a dataset with 0 observations. Can i remove them or have some condition for not creating them if condition is not satisfied.?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using the belwo code:&lt;/P&gt;&lt;PRE&gt;proc datasets nolist;
	copy in=analysis out=work;
quit;
run;

%*split the data into different folders based on fold;
data _null_;
  set sashelp.vtable (where=(libname="WORK"));
  call execute('data sa.'||strip(memname)||'; set WORK.'||strip(memname)||'; where fold="19A"; run;');
  call execute('data s1a.'||strip(memname)||'; set WORK.'||strip(memname)||'; where fold="10A"; run;');
  call execute('data s2a.'||strip(memname)||'; set WORK.'||strip(memname)||'; where fold="12A"; run;');
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Oct 2018 08:34:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/is-there-anyway-if-i-can-only-split-datasets-into-different/m-p/508599#M136612</guid>
      <dc:creator>noda6003</dc:creator>
      <dc:date>2018-10-30T08:34:46Z</dc:date>
    </item>
    <item>
      <title>Re: is there anyway if i can only split datasets into different folders based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/is-there-anyway-if-i-can-only-split-datasets-into-different/m-p/508628#M136626</link>
      <description>&lt;P&gt;A cleanup after copying of the tables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Remove empty tables */
data _null_;
  set sashelp.vtable (where=(libname in ("SA","S1A","S2A") and nobs=0));
  call execute(catt('proc delete data=',Libname,'.',Memname,';run;'));
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 30 Oct 2018 10:14:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/is-there-anyway-if-i-can-only-split-datasets-into-different/m-p/508628#M136626</guid>
      <dc:creator>MichaelLarsen</dc:creator>
      <dc:date>2018-10-30T10:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: is there anyway if i can only split datasets into different folders based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/is-there-anyway-if-i-can-only-split-datasets-into-different/m-p/508651#M136638</link>
      <description>&lt;P&gt;You can split your data within one step per dataset:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro split(memname);
    data sa.&amp;amp;memname
           s1a.&amp;amp;memname
           s2a.&amp;amp;memname
     ;
      set work.&amp;amp;memname;
          if folder = '19A' then output sa.&amp;amp;memname; else
          if folder = '10A' then output s1a.&amp;amp;memname; else
          if folder = '12A' then output s2a.&amp;amp;memname;
          else delete;
   run;
%mend split;
%split(&amp;lt;mem1&amp;gt;);
%split(&amp;lt;mem2&amp;gt;);
...    &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;thus will save I/O - each observation you'll read only once and write it to output.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 12:24:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/is-there-anyway-if-i-can-only-split-datasets-into-different/m-p/508651#M136638</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2018-10-30T12:24:53Z</dc:date>
    </item>
    <item>
      <title>Re: is there anyway if i can only split datasets into different folders based on conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/is-there-anyway-if-i-can-only-split-datasets-into-different/m-p/508661#M136641</link>
      <description>&lt;P&gt;I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp;performance might be an issue, so avoid I/O as much as possible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of creating a macro, I have made an example that writes the data step code that does the copying and then include that code afterwards to execute the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename pgm temp;
%let copylib=ANALYSIS;
data _null_;
  set sashelp.vtable;
  where Libname = "&amp;amp;Copylib" and nobs &amp;gt; 0;
  file pgm;
  put 'data sa.' memname
    / '     s1a.' memname
    / '     s2a.' memname ';' 
    / '  set ' "&amp;amp;Copylib.." memname ';'
    / '  if fold = "19A" then output sa.' memname ';'
    / '  else if fold = "10A" then output s1a.' memname ';'
    / '  else if fold = "12A" then output s2a.' memname ';'
    / 'run;'
    ;
run;
%inc pgm / Source2;
filename pgm clear;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I created the COPYLIB macro variable to be able to test it on another library.&lt;/P&gt;</description>
      <pubDate>Tue, 30 Oct 2018 12:50:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/is-there-anyway-if-i-can-only-split-datasets-into-different/m-p/508661#M136641</guid>
      <dc:creator>MichaelLarsen</dc:creator>
      <dc:date>2018-10-30T12:50:46Z</dc:date>
    </item>
  </channel>
</rss>

