<?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: Appending dataset in Macro loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Appending-dataset-in-Macro-loop/m-p/311612#M67398</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Appending the above dataset using Do loop */

%MACRO TEST;

           %DO i=1 %TO 3 ;

  %If &amp;amp;i.=1 %Then %Do;
  Data Append_DT;
    Set A_&amp;amp;i.;
  Run;
  %End;
  %Else %Do;
  Proc Append Base=Append_DT Data=A_&amp;amp;i.;
  Run;
  * OR:;
/*  Data Append_DT;*/
/*    Set Append_DT A_&amp;amp;i.;*/
/*  Run;*/
  %End;
%END;

PROC PRINT DATA = APPEND_DT;
RUN;

%MEND;

%TEST;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 15 Nov 2016 06:30:03 GMT</pubDate>
    <dc:creator>user24feb</dc:creator>
    <dc:date>2016-11-15T06:30:03Z</dc:date>
    <item>
      <title>Appending dataset in Macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-dataset-in-Macro-loop/m-p/311607#M67396</link>
      <description>&lt;P&gt;Hi ,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want&amp;nbsp;to append the dataset A_1 , A_2 , A_3 to a New dataset called APPEND_DT .Trying to pass the parameters through macro do loop , but setting the dataset &amp;nbsp;for each time APPEND_DT is overwritten .&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Help me in this !&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;EM&gt;&lt;STRONG&gt;Program:&lt;/STRONG&gt;&lt;/EM&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;/** Sample DATASET 1 **/&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;DATA A_1;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;input ID ;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;datalines;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;1&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;2&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;3&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;4&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;RUN;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;/** Sample DATASET 2 **/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;DATA A_2;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;input ID ;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;datalines;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;5&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;6&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;RUN;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;/** Sample DATASET 3 **/&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;DATA A_3;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;input ID ;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;datalines;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;7&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;8&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;9&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;RUN;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;/* Appending the above dataset using Do loop */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;%MACRO TEST;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;%DO i=1 %TO 3 ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PROC PRINT DATA = A_&amp;amp;i.;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;RUN;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DATA APPEND_DT;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SET A_&amp;amp;i.;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;RUN;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;%END;&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;PROC PRINT DATA = APPEND_DT;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;RUN;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;%MEND;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="1 2 3 4 5 6 7"&gt;%TEST;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Desired OP:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&lt;/P&gt;&lt;P&gt;2&lt;/P&gt;&lt;P&gt;3&lt;/P&gt;&lt;P&gt;4&lt;/P&gt;&lt;P&gt;5&lt;/P&gt;&lt;P&gt;6&lt;/P&gt;&lt;P&gt;7&lt;/P&gt;&lt;P&gt;8&lt;/P&gt;&lt;P&gt;9&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2016 06:13:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-dataset-in-Macro-loop/m-p/311607#M67396</guid>
      <dc:creator>monikka1991</dc:creator>
      <dc:date>2016-11-15T06:13:11Z</dc:date>
    </item>
    <item>
      <title>Re: Appending dataset in Macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-dataset-in-Macro-loop/m-p/311612#M67398</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Appending the above dataset using Do loop */

%MACRO TEST;

           %DO i=1 %TO 3 ;

  %If &amp;amp;i.=1 %Then %Do;
  Data Append_DT;
    Set A_&amp;amp;i.;
  Run;
  %End;
  %Else %Do;
  Proc Append Base=Append_DT Data=A_&amp;amp;i.;
  Run;
  * OR:;
/*  Data Append_DT;*/
/*    Set Append_DT A_&amp;amp;i.;*/
/*  Run;*/
  %End;
%END;

PROC PRINT DATA = APPEND_DT;
RUN;

%MEND;

%TEST;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Nov 2016 06:30:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-dataset-in-Macro-loop/m-p/311612#M67398</guid>
      <dc:creator>user24feb</dc:creator>
      <dc:date>2016-11-15T06:30:03Z</dc:date>
    </item>
    <item>
      <title>Re: Appending dataset in Macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-dataset-in-Macro-loop/m-p/311615#M67399</link>
      <description>&lt;P&gt;Yes, it will recreate a new dataset each time that's only the current values. It needs to be something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set want a_1;&lt;/P&gt;
&lt;P&gt;run;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But in this case want has to already exist. A common workaround is to say if n=1 then&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;set a_1;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set want A_&amp;amp;i;&lt;/P&gt;
&lt;P&gt;run;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Better yet, avoid macros entirely unless you enjoy obfuscating code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data append_dt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;Set a_1 - a_3;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2016 06:50:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-dataset-in-Macro-loop/m-p/311615#M67399</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-15T06:50:33Z</dc:date>
    </item>
    <item>
      <title>Re: Appending dataset in Macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-dataset-in-Macro-loop/m-p/311629#M67409</link>
      <description>&lt;P&gt;PROC APPEND assumes that base table and new data table have same variables (otherwise use option FORCE).&lt;/P&gt;
&lt;P&gt;If base table does not exist, the proc will copy first appaended table to be the base.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your example, you created 3 tables A_1 A_2 A_3;&lt;/P&gt;
&lt;P&gt;So your program should be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets lib=work nolist;  /* to be done first time only */
       delete append_dt;    /* do not care if you get message that table does not exist */&lt;BR /&gt;quit; run;&lt;BR /&gt;&lt;BR /&gt;%macro append_all;&lt;BR /&gt;    %do i=1 %to 3;&lt;BR /&gt;        proc append base=append_dt data=A_&amp;amp;i; run;&lt;BR /&gt;    %end;&lt;BR /&gt;%mend append_all;&lt;BR /&gt;%append_all;&lt;BR /&gt;proc print data=append_dt; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2016 09:46:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-dataset-in-Macro-loop/m-p/311629#M67409</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-11-15T09:46:19Z</dc:date>
    </item>
    <item>
      <title>Re: Appending dataset in Macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-dataset-in-Macro-loop/m-p/311671#M67432</link>
      <description>&lt;P&gt;Sorry, I am not seeing why you would need macro? &amp;nbsp;Something simple like:&lt;/P&gt;
&lt;PRE&gt;data want;
  set append_dt a_:;
run;&lt;/PRE&gt;
&lt;P&gt;Will do the job without all that kurfuffle. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2016 13:25:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-dataset-in-Macro-loop/m-p/311671#M67432</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-11-15T13:25:17Z</dc:date>
    </item>
    <item>
      <title>Re: Appending dataset in Macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-dataset-in-Macro-loop/m-p/311717#M67450</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9﻿&lt;/a&gt;&amp;nbsp;your note is interesting.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have checked it on SAS UE and got ERROR pointint at the &lt;FONT color="#FF0000"&gt;&amp;nbsp;:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;56 options nonotes;&lt;BR /&gt; 57 data test1; x=1; output; run;&lt;BR /&gt; 58 data test2; x=2; output; run;&lt;BR /&gt; 59 &lt;BR /&gt; 60 proc append base=all_test&lt;BR /&gt; 61 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;data = test:;&lt;BR /&gt;&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;_&lt;BR /&gt;&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; 22&lt;BR /&gt;&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; 200&lt;BR /&gt; ERROR: File WORK.TEST.DATA does not exist.&lt;BR /&gt; ERROR 22-322: Syntax error, expecting one of the following: ;, (, APPENDVER, APPENDVERSION, BASE, CREATE, DATA, FORCE, GETSORT, &lt;BR /&gt; NEW, NOWARN, OUT. &lt;BR /&gt; &lt;STRONG&gt;ERROR 200-322: The symbol is not recognized and will be ignored.&lt;/STRONG&gt;&lt;BR /&gt; 62 run cancel;&lt;BR /&gt; WARNING: The procedure was not executed at the user's request.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2016 14:55:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-dataset-in-Macro-loop/m-p/311717#M67450</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-11-15T14:55:15Z</dc:date>
    </item>
    <item>
      <title>Re: Appending dataset in Macro loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Appending-dataset-in-Macro-loop/m-p/311729#M67452</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I assumed (incorrectly it appears) that lists would work in that. &amp;nbsp;Its seems not, and that makes sense as it is a procedure with parameters. &amp;nbsp;Of course it works fine in a datastep, so the same thing:&lt;/P&gt;
&lt;PRE&gt;data test1;
  a=1;
run;
data test2;
  a=2;
run;
data want;
  set test:;
run;
&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Nov 2016 15:20:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Appending-dataset-in-Macro-loop/m-p/311729#M67452</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-11-15T15:20:50Z</dc:date>
    </item>
  </channel>
</rss>

