<?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: Macro to combine multiple datasets with different names in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-combine-multiple-datasets-with-different-names/m-p/434430#M107802</link>
    <description>thanks Astounding. I'll try this code. will post an update later.</description>
    <pubDate>Tue, 06 Feb 2018 00:37:09 GMT</pubDate>
    <dc:creator>sasRus</dc:creator>
    <dc:date>2018-02-06T00:37:09Z</dc:date>
    <item>
      <title>Macro to combine multiple datasets with different names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-combine-multiple-datasets-with-different-names/m-p/434417#M107794</link>
      <description>&lt;P&gt;Hi there, SAS newbie here. I have a SAS library of 40+ files the following dataset name pattern:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;McDonalds&lt;/P&gt;&lt;P&gt;McDonaldsFile2&lt;/P&gt;&lt;P&gt;BurgerKing&lt;/P&gt;&lt;P&gt;Wendys&lt;/P&gt;&lt;P&gt;WendysFile2&lt;/P&gt;&lt;P&gt;WendysFile3&lt;/P&gt;&lt;P&gt;PizzaHut&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All of these files share the same column names. So some companies have just one file, whereas others have more than one file. I am trying to write a macro to combine each company’s files into one dataset. So&amp;nbsp;McDonalds = McDonalds + McDonaldsFile2, and Wendys = Wendys + WendysFile2 + WendysFile3. The other companies with just one file should stay intact.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the code I’ve tried:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=abc._all_ out=abccont(keep=memname) noprint;
run;

proc sort data=abccont nodupkey;
by memname;
run;

data _null_;
set abccont end=last;
by memname;
i+1;
call symputx('name'||trim(left(put(i,8.))),memname);
if last then call symputx('count',i);
run;

%macro combine;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%do n = 1 %to &amp;amp;count;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data &amp;amp;memname;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do&amp;nbsp;j = 2 %to 3;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cats(&amp;amp;memname,’File’,&amp;amp;i);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;
%mend combine;

%combine;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have spent hours searching the forums and google, but to no avail. Any help would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 23:26:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-combine-multiple-datasets-with-different-names/m-p/434417#M107794</guid>
      <dc:creator>sasRus</dc:creator>
      <dc:date>2018-02-05T23:26:26Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to combine multiple datasets with different names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-combine-multiple-datasets-with-different-names/m-p/434420#M107796</link>
      <description>&lt;P&gt;If they all have the same variables this approach will work - no macros needed:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=abc._all_ out=abccont(keep=memname) noprint;
run;

proc sort data=abccont nodupkey;
by memname;
run;

proc sql noprint;
select catx(".", 'abc', memname) into :dsn_list separated by " " from abccont;
quit;

data combined_data;
set &amp;amp;dsn_list;
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Replace ABC in the CATX with the libname you actually have and this should work&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/191085"&gt;@sasRus&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi there, SAS newbie here. I have a SAS library of 40+ files the following dataset name pattern:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;McDonalds&lt;/P&gt;
&lt;P&gt;McDonaldsFile2&lt;/P&gt;
&lt;P&gt;BurgerKing&lt;/P&gt;
&lt;P&gt;Wendys&lt;/P&gt;
&lt;P&gt;WendysFile2&lt;/P&gt;
&lt;P&gt;WendysFile3&lt;/P&gt;
&lt;P&gt;PizzaHut&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All of these files share the same column names. So some companies have just one file, whereas others have more than one file. I am trying to write a macro to combine each company’s files into one dataset. So&amp;nbsp;McDonalds = McDonalds + McDonaldsFile2, and Wendys = Wendys + WendysFile2 + WendysFile3. The other companies with just one file should stay intact.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the code I’ve tried:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=abc._all_ out=abccont(keep=memname) noprint;
run;

proc sort data=abccont nodupkey;
by memname;
run;

data _null_;
set abccont end=last;
by memname;
i+1;
call symputx('name'||trim(left(put(i,8.))),memname);
if last then call symputx('count',i);
run;

%macro combine;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%do n = 1 %to &amp;amp;count;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data &amp;amp;memname;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do&amp;nbsp;j = 2 %to 3;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cats(&amp;amp;memname,’File’,&amp;amp;i);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;
%mend combine;

%combine;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have spent hours searching the forums and google, but to no avail. Any help would be appreciated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 23:35:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-combine-multiple-datasets-with-different-names/m-p/434420#M107796</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-05T23:35:15Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to combine multiple datasets with different names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-combine-multiple-datasets-with-different-names/m-p/434423#M107798</link>
      <description>&lt;P&gt;I think what you are asking for is a set of SAS data sets, not a single SAS data set holding all the data.&amp;nbsp; Under that assumption, here is an approach.&amp;nbsp; It's untested code, so may need some tweaking.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; create table dataset_list as select distinct memname from dictionary.tables where upcase(libname)='ABC';&lt;/P&gt;
&lt;P&gt;&amp;nbsp; ** Because of the use of DISTINCT, the list should be in alphabetical order ... if not, add order by memname clause;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data dataset_list;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set dataset_list;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;position = length(memname) - 4;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if substr(memname, position) =: 'File' then root = substr(memname, 1, position-1);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;else root = memname;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;set dataset_list;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;by root;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;if first.root=0 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; call execute('proc append data=abc.' || memname || ' base = abc.' || root || '; run;') ) ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Make sure your data is backed up (or replaceable) since this replaces permanent data sets, but uses untested code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 23:57:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-combine-multiple-datasets-with-different-names/m-p/434423#M107798</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-02-05T23:57:07Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to combine multiple datasets with different names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-combine-multiple-datasets-with-different-names/m-p/434429#M107801</link>
      <description>hi Reeza, thank you for your response. I'm not trying to append datasets together, just the ones for each company.</description>
      <pubDate>Tue, 06 Feb 2018 00:36:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-combine-multiple-datasets-with-different-names/m-p/434429#M107801</guid>
      <dc:creator>sasRus</dc:creator>
      <dc:date>2018-02-06T00:36:47Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to combine multiple datasets with different names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-combine-multiple-datasets-with-different-names/m-p/434430#M107802</link>
      <description>thanks Astounding. I'll try this code. will post an update later.</description>
      <pubDate>Tue, 06 Feb 2018 00:37:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-combine-multiple-datasets-with-different-names/m-p/434430#M107802</guid>
      <dc:creator>sasRus</dc:creator>
      <dc:date>2018-02-06T00:37:09Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to combine multiple datasets with different names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-combine-multiple-datasets-with-different-names/m-p/434434#M107805</link>
      <description>&lt;P&gt;Ok...similar approach but there’s no real way to know if Wendy’s and McDonalds are different.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I guess you you could convert my previous code into a macro and add a LIKE condition to selectively group the names based on the first 5 or X characters.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 00:55:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-combine-multiple-datasets-with-different-names/m-p/434434#M107805</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-06T00:55:45Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to combine multiple datasets with different names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-combine-multiple-datasets-with-different-names/m-p/434462#M107817</link>
      <description>&lt;P&gt;You don't seem to understand the difference between macro code and the SAS code that you are trying to use it to generate.&lt;/P&gt;
&lt;P&gt;For example it looks like you tried to stick a data step function call into the middle of a SET statement.&lt;/P&gt;
&lt;P&gt;So macro code like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data &amp;amp;memname;
  set
%do j = 2 %to 3;
  cats(&amp;amp;memname,’File’,&amp;amp;i);
%end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So if the macro variable MEMNAME had the value WENDYS it would try to generate SAS code that looked like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WENDYS;
  set
  cats(WENDYS,’File’,2);
  cats(WENDYS,’File’,3);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So you are telling SAS to set a dataset named CATS and then are adding an invalid set of data set options.&amp;nbsp; Then you are calling the CATS() function, but you have not used in a valid SAS statement since there is no variable that you are assigning the result into.&amp;nbsp; Also the variable WENDYS that the CATS() function is referencing has not been defined.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Don't try to use macro code to generate code until you know what code you want to generate.&lt;/P&gt;
&lt;P&gt;If you want to create a new dataset from every dataset that starts with a specific prefix then just use the new colon modifier on a set statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.wendys;
  set abc.wendys: ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you could get in trouble if some full names match the beginning of other names.&lt;/P&gt;
&lt;P&gt;If your pattern is name the groups as X, XFILE2, XFILE3, .... then perhaps you have some hope of automating the process.&lt;/P&gt;
&lt;P&gt;But really for 40 files (so what 13 to 30 actual groups?) it is probably going to be faster and easier just to copy the simple dataset above and edit it by hand.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 05:42:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-combine-multiple-datasets-with-different-names/m-p/434462#M107817</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-02-06T05:42:40Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to combine multiple datasets with different names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-combine-multiple-datasets-with-different-names/m-p/434533#M107835</link>
      <description>&lt;P&gt;You want a create a program that looks like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data newlib.mcdonalds;
  set oldlib.mcdonalds:  open=defer;
run;
data newlib.wendys;
  set oldlib.wendys:  open=defer;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;OL&gt;
&lt;LI&gt;The trailing colon tells sas you are using a name root, you want all datasets whose names begin with the text preceding the colon.&lt;/LI&gt;
&lt;LI&gt;The "open=defer"&amp;nbsp; tells SAS to re-use one buffer for each incoming data set, instead of making a buffer for each.&amp;nbsp; But it assumes that all the data sets have the same variables.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;To construct such a program:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set memlist;
  root=prxchange('s/(\w+)FILE\d+\s/$1/',1,upcase(memname));
  if root ^= lag(root) then 
    call execute(catx(' ','DATA',root,';SET',cats(root,': open=defer;run;')));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the perl regular expression (prx) function is too opaque, you can generate the root value as below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set memlist;
  root=upcase(memname);
  do while ('0'&amp;lt;=char(root,length(root))&amp;lt;='9');
    root=substr(root,1,length(root)-1);
  end;
  root=transtrn(root,'FILE ','     ');
  if root ^= lag(root) then 
    call execute(catx(' ','DATA',root,';SET',cats(root,': open=defer;run;')));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 06 Feb 2018 14:03:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-combine-multiple-datasets-with-different-names/m-p/434533#M107835</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-02-06T14:03:07Z</dc:date>
    </item>
    <item>
      <title>Re: Macro to combine multiple datasets with different names</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-to-combine-multiple-datasets-with-different-names/m-p/434625#M107870</link>
      <description>&lt;P&gt;thank you for your solutions Tom and mkeintz. I was able to get my solution by tweaking some of Astounding's code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
&amp;nbsp; create table dataset_list as select distinct memname from dictionary.tables where upcase(libname)='ABC';
&amp;nbsp; ** Because of the use of DISTINCT, the list should be in alphabetical order ... if not, add order by memname clause;
quit;

data dataset_list;
   set dataset_list;
   position = length(memname) - 4;
   if substr(memname, position) =: 'File' then root = substr(memname, 1, position-1);
   else root = memname;
run;

 
data _null_;
   set dataset_list;
   by root;
   if first.root=0 then do;
      call execute('proc append data=staging.' || memname || ' base = staging.' || root || ' force; run;' ) ;
   end;
run;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Feb 2018 18:01:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-to-combine-multiple-datasets-with-different-names/m-p/434625#M107870</guid>
      <dc:creator>sasRus</dc:creator>
      <dc:date>2018-02-06T18:01:10Z</dc:date>
    </item>
  </channel>
</rss>

