<?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: read all datasets in a library and conditionally split them in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/read-all-datasets-in-a-library-and-conditionally-split-them/m-p/463340#M118040</link>
    <description>&lt;P&gt;Thanks a lot. Instead of dataset name as 1 ,2 and 3 can i place them in seperate folders as i made libname inc "path"; libname ind "path";&lt;/P&gt;
&lt;P&gt;libname ing "path";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 18 May 2018 13:53:14 GMT</pubDate>
    <dc:creator>vraj1</dc:creator>
    <dc:date>2018-05-18T13:53:14Z</dc:date>
    <item>
      <title>read all datasets in a library and conditionally split them</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-all-datasets-in-a-library-and-conditionally-split-them/m-p/463317#M118026</link>
      <description>&lt;P&gt;I have datasets in library and need to conditionally split all of them into 3 parts.&lt;/P&gt;
&lt;P&gt;Ex- aghs consists union = "first" "second" "third"&amp;nbsp;&lt;/P&gt;
&lt;P&gt;libraries inc, ind, inf&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if for aghs and union="first" then it should go to inc&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;if for aghs and union="second" then it should go to ind&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;if for aghs and union="third" then it should go to inf&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;i have more than one dataset. How can i optimally do this.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Any help please.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 13:25:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-all-datasets-in-a-library-and-conditionally-split-them/m-p/463317#M118026</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2018-05-18T13:25:40Z</dc:date>
    </item>
    <item>
      <title>Re: read all datasets in a library and conditionally split them</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-all-datasets-in-a-library-and-conditionally-split-them/m-p/463331#M118034</link>
      <description>&lt;P&gt;Don't, its never a good idea to split same data into smaller bits, it takes more disk space, more resources, makes your coding life harder.&lt;/P&gt;
&lt;P&gt;That said:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set sashelp.vtable (where=(libname="YOURLIB"));
  call execute('data '||strip(memname)||'1; set yourlib.'||strip(memname)||'; where union="first"; run;');
  call execute('data '||strip(memname)||'2; set yourlib.'||strip(memname)||'; where union="second"; run;');
  call execute('data '||strip(memname)||'3; set yourlib.'||strip(memname)||'; where union="third"; run;');
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 May 2018 13:39:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-all-datasets-in-a-library-and-conditionally-split-them/m-p/463331#M118034</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-05-18T13:39:13Z</dc:date>
    </item>
    <item>
      <title>Re: read all datasets in a library and conditionally split them</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-all-datasets-in-a-library-and-conditionally-split-them/m-p/463334#M118035</link>
      <description>&lt;P&gt;Write a datastep that splits one:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data
  inc.dataset
  ind.dataset
  inf.dataset
;
set aghs.dataset;
select (union);
  when ('first') output inc.dataset;
  when('second) output ind.dataset;
  when ('third') output inf.dataset;
  otherwise; /* for safety, remove if you want a tripwire */
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;identifiy variable parts, and use macro variable(s):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dataset=dataset;

data
  inc.&amp;amp;dataset
  ind.&amp;amp;dataset
  inf.&amp;amp;dataset
;
set aghs.&amp;amp;dataset;
select (union);
  when ('first') output inc.&amp;amp;dataset;
  when('second) output ind.&amp;amp;dataset;
  when ('third') output inf.&amp;amp;dataset;
  otherwise; /* for safety, remove if you want a tripwire */
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;convert to a macro:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro split_data(dataset);

data
  inc.&amp;amp;dataset
  ind.&amp;amp;dataset
  inf.&amp;amp;dataset
;
set aghs.&amp;amp;dataset;
select (union);
  when ('first') output inc.&amp;amp;dataset;
  when('second) output ind.&amp;amp;dataset;
  when ('third') output inf.&amp;amp;dataset;
  otherwise; /* for safety, remove if you want a tripwire */
end;
run;

%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you need to create a dataset of datasets for your library:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table control as
select memname from dictionary.tables
where libname = 'AGHS';
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and call your macro off that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set control;
call execute('%split_data(' !! strip(memname) !! ');');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 May 2018 13:43:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-all-datasets-in-a-library-and-conditionally-split-them/m-p/463334#M118035</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-05-18T13:43:44Z</dc:date>
    </item>
    <item>
      <title>Re: read all datasets in a library and conditionally split them</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-all-datasets-in-a-library-and-conditionally-split-them/m-p/463337#M118037</link>
      <description>&lt;P&gt;Thanks, it is an integrated database and i want to seperate them and place them in seperate folders.&lt;/P&gt;
&lt;P&gt;the code which you have provided gives&lt;/P&gt;
&lt;P&gt;NOTE: The map data sets in library MAPSGFK are based on the digital maps from GfK GeoMarketing and are covered by their Copyright. For additional information, see&lt;BR /&gt; &lt;A href="http://support.sas.com/mapsonline/gfklicense" target="_blank"&gt;http://support.sas.com/mapsonline/gfklicense&lt;/A&gt;.&lt;BR /&gt;NOTE: There were 0 observations read from the data set SASHELP.VTABLE.&lt;BR /&gt; WHERE libname='work';&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 13:48:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-all-datasets-in-a-library-and-conditionally-split-them/m-p/463337#M118037</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2018-05-18T13:48:02Z</dc:date>
    </item>
    <item>
      <title>Re: read all datasets in a library and conditionally split them</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-all-datasets-in-a-library-and-conditionally-split-them/m-p/463338#M118038</link>
      <description>&lt;P&gt;"&lt;SPAN&gt;NOTE: There were 0 observations read from the data set SASHELP.VTABLE.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;WHERE libname='work';"&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Check your where clause, libnames need to be in uppercase.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 13:50:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-all-datasets-in-a-library-and-conditionally-split-them/m-p/463338#M118038</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-05-18T13:50:14Z</dc:date>
    </item>
    <item>
      <title>Re: read all datasets in a library and conditionally split them</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-all-datasets-in-a-library-and-conditionally-split-them/m-p/463339#M118039</link>
      <description>&lt;P&gt;In the dictionary tables (and the sashelp views based on them), library and dataset names are always in capitals.&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 13:50:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-all-datasets-in-a-library-and-conditionally-split-them/m-p/463339#M118039</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-05-18T13:50:40Z</dc:date>
    </item>
    <item>
      <title>Re: read all datasets in a library and conditionally split them</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-all-datasets-in-a-library-and-conditionally-split-them/m-p/463340#M118040</link>
      <description>&lt;P&gt;Thanks a lot. Instead of dataset name as 1 ,2 and 3 can i place them in seperate folders as i made libname inc "path"; libname ind "path";&lt;/P&gt;
&lt;P&gt;libname ing "path";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 13:53:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-all-datasets-in-a-library-and-conditionally-split-them/m-p/463340#M118040</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2018-05-18T13:53:14Z</dc:date>
    </item>
    <item>
      <title>Re: read all datasets in a library and conditionally split them</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-all-datasets-in-a-library-and-conditionally-split-them/m-p/463342#M118042</link>
      <description>&lt;P&gt;i use the below libnames but it doesnt work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt; set sashelp.vtable (where=(libname="WORK"));&lt;BR /&gt; call execute('data inc.'||strip(memname)'; set WORK.'||strip(memname)||'; where studyid="12709A"; run;');&lt;BR /&gt; call execute('data&amp;nbsp; ind.'||strip(memname)'; set WORK.'||strip(memname)||'; where studyid="12710A"; run;');&lt;BR /&gt; call execute('data ing.'||strip(memname)'; set WORK.'||strip(memname)||'; where studyid="12712A"; run;');&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 14:00:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-all-datasets-in-a-library-and-conditionally-split-them/m-p/463342#M118042</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2018-05-18T14:00:12Z</dc:date>
    </item>
    <item>
      <title>Re: read all datasets in a library and conditionally split them</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-all-datasets-in-a-library-and-conditionally-split-them/m-p/463344#M118043</link>
      <description>&lt;P&gt;Of course, just change the generated code, call execute() is just a string, which is run as code after the datastep executes:&lt;/P&gt;
&lt;PRE&gt;data _null_;
  set sashelp.vtable (where=(libname="YOURLIB"));
  call execute('data inc.'||strip(memname)||'; set yourlib.'||strip(memname)||'; where union="first"; run;');
  call execute('data ind.'||strip(memname)||'; set yourlib.'||strip(memname)||'; where union="second"; run;');
  call execute('data ing.'||strip(memname)||'; set yourlib.'||strip(memname)||'; where union="third"; run;');
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 May 2018 14:00:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-all-datasets-in-a-library-and-conditionally-split-them/m-p/463344#M118043</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-05-18T14:00:50Z</dc:date>
    </item>
    <item>
      <title>Re: read all datasets in a library and conditionally split them</title>
      <link>https://communities.sas.com/t5/SAS-Programming/read-all-datasets-in-a-library-and-conditionally-split-them/m-p/463345#M118044</link>
      <description>&lt;P&gt;"Doesn't work" - does not tell us anything.&amp;nbsp; What does the log say?&amp;nbsp; You should have three datasteps for each dataset in work.&amp;nbsp; Is the where clauses correct?&lt;/P&gt;</description>
      <pubDate>Fri, 18 May 2018 14:02:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/read-all-datasets-in-a-library-and-conditionally-split-them/m-p/463345#M118044</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-05-18T14:02:49Z</dc:date>
    </item>
  </channel>
</rss>

