<?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/loop to concatenate multiple datasets - proc append? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-loop-to-concatenate-multiple-datasets-proc-append/m-p/429604#M281526</link>
    <description>&lt;P&gt;Why do you have multiple datasets all the same, but for different periods in the first place?&amp;nbsp; It is&amp;nbsp;rarely if ever that splitting data up doe sanything more than multiply up the resources needed, and the cost or writing lots of code.&amp;nbsp; SAS provides something called by group processing to exactly this task, with minimal coding/maintenance, and low resource costs so best to use that.&amp;nbsp; So fix the steps before the data results, to instead of being some big loop creating lots of datasets, to one dataset which has period as a variable and then do:&lt;/P&gt;
&lt;P&gt;by period;&lt;/P&gt;
&lt;P&gt;On your steps.&lt;/P&gt;</description>
    <pubDate>Mon, 22 Jan 2018 13:33:18 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-01-22T13:33:18Z</dc:date>
    <item>
      <title>macro/loop to concatenate multiple datasets - proc append?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-loop-to-concatenate-multiple-datasets-proc-append/m-p/429588#M281522</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a very simple problem, but it's bugging me. I have multiple datasets with same number of columns and column name that I want to merge vertically. The following code works:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data results;
set result_period_1 result_period_2 result_period_3;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;However, total no of periods is a lot, and I want to have a simple macro/loop that achieves the same thing. I tried proc append, but didn't work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro append;
      proc append base=results_period_1 data=
   %do  i =  1 %to 3;
         results_period_&amp;amp;i
   %end;
 run;
%mend append;

%append;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Appreciate your help!&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jan 2018 12:08:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-loop-to-concatenate-multiple-datasets-proc-append/m-p/429588#M281522</guid>
      <dc:creator>ss59</dc:creator>
      <dc:date>2018-01-22T12:08:22Z</dc:date>
    </item>
    <item>
      <title>Re: macro/loop to concatenate multiple datasets - proc append?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-loop-to-concatenate-multiple-datasets-proc-append/m-p/429592#M281523</link>
      <description>&lt;P&gt;Why not use the same datastep code as base for your macro?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro append;
data results;
set
%do  i =  1 %to 3;
  results_period_&amp;amp;i
%end;
;
run;
%mend append;

%append;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or use call execute():&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
call execute('data results; set');
do i = 1 to 3;
  call execute(' results_period_' !! strip(put(i,best.)));
end;
call execute('; run;');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 22 Jan 2018 12:18:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-loop-to-concatenate-multiple-datasets-proc-append/m-p/429592#M281523</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-01-22T12:18:25Z</dc:date>
    </item>
    <item>
      <title>Re: macro/loop to concatenate multiple datasets - proc append?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-loop-to-concatenate-multiple-datasets-proc-append/m-p/429593#M281524</link>
      <description>&lt;P&gt;You cannot append more than one dataset at a time; you will have to have one PROC APPEND invocation for each table, e.g.:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro append;
  %local i;
  %do  i =  1 %to 3;
    proc append base=results data=results_period_&amp;amp;i;
    run;
    %end;
%mend append;

%append;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I changed the BASE to RESULTS, your original code looked like it was going to append results_period_1 to itself (you can do that, but that's probably not what you want). If the BASE table does not exist initially, it will be created, no problem about that. You may even want to put in a PROC DELETE DATA=RESULTS in before the APPEND loop, in case&amp;nbsp; you run the code several times.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And you will save yourself a lot of trouble in the long run by declaring local macro variables %LOCAL!&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jan 2018 12:19:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-loop-to-concatenate-multiple-datasets-proc-append/m-p/429593#M281524</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-01-22T12:19:46Z</dc:date>
    </item>
    <item>
      <title>Re: macro/loop to concatenate multiple datasets - proc append?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-loop-to-concatenate-multiple-datasets-proc-append/m-p/429594#M281525</link>
      <description>&lt;P&gt;Untested, be sure that "results" does not exist:&lt;/P&gt;
&lt;PRE&gt;%macro append;
   %do  i =  1 %to 3;
      proc append base=results data=results_period_&amp;amp;i.;
      run;
   %end;
%mend append;

%append;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;data results;
set result_period_:;
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jan 2018 12:21:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-loop-to-concatenate-multiple-datasets-proc-append/m-p/429594#M281525</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-01-22T12:21:37Z</dc:date>
    </item>
    <item>
      <title>Re: macro/loop to concatenate multiple datasets - proc append?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-loop-to-concatenate-multiple-datasets-proc-append/m-p/429604#M281526</link>
      <description>&lt;P&gt;Why do you have multiple datasets all the same, but for different periods in the first place?&amp;nbsp; It is&amp;nbsp;rarely if ever that splitting data up doe sanything more than multiply up the resources needed, and the cost or writing lots of code.&amp;nbsp; SAS provides something called by group processing to exactly this task, with minimal coding/maintenance, and low resource costs so best to use that.&amp;nbsp; So fix the steps before the data results, to instead of being some big loop creating lots of datasets, to one dataset which has period as a variable and then do:&lt;/P&gt;
&lt;P&gt;by period;&lt;/P&gt;
&lt;P&gt;On your steps.&lt;/P&gt;</description>
      <pubDate>Mon, 22 Jan 2018 13:33:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-loop-to-concatenate-multiple-datasets-proc-append/m-p/429604#M281526</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-01-22T13:33:18Z</dc:date>
    </item>
  </channel>
</rss>

