<?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: Proc Append multiple data sets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685255#M207806</link>
    <description>&lt;P&gt;I have shown you the use of CALL EXECUTE repeatedly, for instance here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/let-ListDates-and-run-multiple-case-when-statements/td-p/616767" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/let-ListDates-and-run-multiple-case-when-statements/td-p/616767&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 20 Sep 2020 09:16:31 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-09-20T09:16:31Z</dc:date>
    <item>
      <title>Proc Append multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685238#M207795</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I know that proc append can append no more than 2 data sets.&lt;/P&gt;
&lt;P&gt;I want to ask in a situation when I have for example 5 data sets called:&lt;/P&gt;
&lt;P&gt;tbl1,tbl2,tbl3,tbl4,tbl5&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In such case I can run 4 proc append statements.&lt;/P&gt;
&lt;P&gt;Proc append base=tbl2 data=tbl1;run;&lt;/P&gt;
&lt;P&gt;Proc append base=tbl2 data=tbl3;run;&lt;/P&gt;
&lt;P&gt;Proc append base=tbl2 data=tbl4;run;&lt;/P&gt;
&lt;P&gt;Proc append base=tbl2 data=tbl5;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Question1:&lt;/P&gt;
&lt;P&gt;Is there a way to create macro that make these proc appends automatically?&lt;/P&gt;
&lt;P&gt;In real world when I have for example 100 data sets&amp;nbsp; then It is better to create macro that append it instead of typing 99 proc append's&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Question2:&lt;/P&gt;
&lt;P&gt;The name of the output data set in this example is tbl2.&lt;/P&gt;
&lt;P&gt;Is there a way to rename the output wanted dataset to "Wanted"?&lt;/P&gt;
&lt;P&gt;Proc append base=tbl2(rename=(tbl2=wanted)&amp;nbsp; data=tbl5;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Sep 2020 05:42:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685238#M207795</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-09-20T05:42:43Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Append multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685239#M207796</link>
      <description>&lt;P&gt;If you have a 100 (or other number) of similar named datasets you might consider using a data step. The Set statement can accept lists of names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Data want;
   set tbl1-tbl100;
run;&lt;/PRE&gt;
&lt;P&gt;Would combine sequentially numbered data sets (no gaps in the numbering).&lt;/P&gt;
&lt;P&gt;Or&lt;/P&gt;
&lt;PRE&gt;Data want;
   set tbl: ;
run;&lt;/PRE&gt;
&lt;P&gt;Would append all data sets whose names start with common base Tbl. They would all have to be in the same library though. &lt;/P&gt;
&lt;P&gt;Either of these can be combined if you several common base names but not all:&lt;/P&gt;
&lt;PRE&gt;Data want;
   set tbl1-tbl15  tbl_2: ;
run;&lt;/PRE&gt;
&lt;P&gt;Would combine the sequential numbered data sets tbl1 through tbl15 and all the tbl_2 named datasets. The sequence group could be in a different library then the tbl_2 sets.&lt;/P&gt;
&lt;P&gt;If the names are "nice" then just a list:&lt;/P&gt;
&lt;PRE&gt;data want; 
    set tbl1 tbl3 tbl27 thatset thisset anotherset;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One advantage of the data set approach is if there are variables that don't appear in all the sets this will work where Proc Append has issues.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For you second question, data set options can't be used to rename anything. You could, with proc append however have the first proc append as&lt;/P&gt;
&lt;PRE&gt;Proc append base=want data=tbl2;
   run;&lt;/PRE&gt;
&lt;P&gt;When the base set does not exist then the append will create it, basically copying tbl2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or use Proc Datasets afterwards to rename a data set.&lt;/P&gt;</description>
      <pubDate>Sun, 20 Sep 2020 06:09:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685239#M207796</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-20T06:09:00Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Append multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685241#M207797</link>
      <description>&lt;P&gt;Thank you.&lt;/P&gt;
&lt;P&gt;Your answer is great but my question was how to create macro that create multiple proc append statements in order to create the desired output.&lt;/P&gt;
&lt;P&gt;I know that there is a way to do it via set statement but my question was how to do it with proc append&lt;/P&gt;
&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Sun, 20 Sep 2020 06:17:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685241#M207797</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-09-20T06:17:02Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Append multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685245#M207798</link>
      <description>&lt;P&gt;Store the names of the datasets to be appended in a dataset, and use CALL EXECUTE to create the APPEND steps.&lt;/P&gt;</description>
      <pubDate>Sun, 20 Sep 2020 07:14:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685245#M207798</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-20T07:14:10Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Append multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685248#M207799</link>
      <description>&lt;P&gt;May you please explain more and show?&lt;/P&gt;
&lt;P&gt;%let list=tbl1+tbl2+tbl3+tbl4+tbl5;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Sep 2020 08:20:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685248#M207799</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-09-20T08:20:38Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Append multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685249#M207800</link>
      <description>&lt;P&gt;Will it work well?&lt;/P&gt;
&lt;P&gt;In the first run of the loop "wanted" data sets doesn't exist. Will it be a problem?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro append;
  %local i;
  %do  i =  1 %to  5;
    proc append base=wanted   data=tbl_&amp;amp;i;
    run;
    %end;
%mend append;
%append;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 20 Sep 2020 08:37:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685249#M207800</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-09-20T08:37:11Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Append multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685250#M207801</link>
      <description>&lt;P&gt;May you please show the full code with Call Execute?&lt;/P&gt;</description>
      <pubDate>Sun, 20 Sep 2020 08:38:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685250#M207801</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-09-20T08:38:43Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Append multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685251#M207802</link>
      <description>&lt;P&gt;As you insist on a macro program and want the output be called "wanted"&amp;nbsp;&lt;/P&gt;
&lt;P&gt;you can use next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets lib=&amp;lt;library&amp;gt; nolist;
    delete wanted;
run;

%macro loop(list);
   %let loop = %sysfunc(countw(&amp;amp;list));
   %do i=1 %to &amp;amp;loop;
          proc append base = wanted data = %scan(&amp;amp;list,&amp;amp;i); run;
   %end;
%mend loop;
%loop( tbl1 tbl2 tbl3 tbl4 tbl5);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 20 Sep 2020 08:46:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685251#M207802</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-09-20T08:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Append multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685252#M207803</link>
      <description>&lt;P&gt;In case all input tables have the same prefix (like TBL) and a sequence number (1 to N)&lt;/P&gt;
&lt;P&gt;then you can adapt he previous code I have sent to:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets lib=&amp;lt;library&amp;gt; nolist;
    delete wanted;
run;

%macro loop(prfix,N);
   %do i=1 %to &amp;amp;N;
          proc append base = wanted data = &amp;amp;prefix.&amp;amp;i); run;
   %end;
%mend loop;
%loop(tbl,5);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 20 Sep 2020 08:47:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685252#M207803</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-09-20T08:47:30Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Append multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685253#M207804</link>
      <description>Great.&lt;BR /&gt;Why is there  ")"  here  &amp;amp;prefix.&amp;amp;i) ?&lt;BR /&gt;was it written by mistake?</description>
      <pubDate>Sun, 20 Sep 2020 09:07:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685253#M207804</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-09-20T09:07:04Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Append multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685254#M207805</link>
      <description>&lt;P&gt;You can work off that macro variable with a %DO loop and %SCAN. We already told you how to do that repeatedly with months stored in your macro list.&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/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;May you please explain more and show?&lt;/P&gt;
&lt;P&gt;%let list=tbl1+tbl2+tbl3+tbl4+tbl5;&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>Sun, 20 Sep 2020 09:13:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685254#M207805</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-20T09:13:34Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Append multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685255#M207806</link>
      <description>&lt;P&gt;I have shown you the use of CALL EXECUTE repeatedly, for instance here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/let-ListDates-and-run-multiple-case-when-statements/td-p/616767" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/let-ListDates-and-run-multiple-case-when-statements/td-p/616767&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Sep 2020 09:16:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685255#M207806</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-09-20T09:16:31Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Append multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685256#M207807</link>
      <description>The ')' is part of the %scan from the previous post.&lt;BR /&gt;Of course it should be removed.</description>
      <pubDate>Sun, 20 Sep 2020 09:43:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685256#M207807</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-09-20T09:43:24Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Append multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685263#M207811</link>
      <description>&lt;P&gt;May you please show also the way of using proc append with call execute?&lt;/P&gt;</description>
      <pubDate>Sun, 20 Sep 2020 11:54:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685263#M207811</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-09-20T11:54:02Z</dc:date>
    </item>
    <item>
      <title>Re: Proc Append multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685270#M207812</link>
      <description>&lt;P&gt;Next code is not tested. Please try it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let prefix = TBL;
%let libin  = WORK;  /* input library */
%let libout = WORK;  /* output library */

proc datasets lib=&amp;lt;library&amp;gt; nolist;
    delete wanted;
run;

data _null_;
  set sashelp.vtable
      (where=(libnmae="&amp;amp;libin" and 
	     substr(memname,1,length(strip("&amp;amp;prefix")))="&amp;amp;prefix));
	   call execute("proc append base = &amp;amp;libout.." || "wanted data = &amp;amp;libin.." || memname || "; run;");                    
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 20 Sep 2020 14:29:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Proc-Append-multiple-data-sets/m-p/685270#M207812</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-09-20T14:29:08Z</dc:date>
    </item>
  </channel>
</rss>

