<?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 appending data in iteration in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/appending-data-in-iteration/m-p/366005#M11034</link>
    <description>&lt;P&gt;Hi I want to append output data from a macro and repeat this process 100 times, how to implement this in SAS? Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro app(n=);&lt;/P&gt;
&lt;P&gt;%do i =1 %to &amp;amp;n;&lt;/P&gt;
&lt;P&gt;%getdata(a=,b=,c=); **** get "outdat" here for each i;&lt;/P&gt;
&lt;P&gt;Proc append base=outdat data=finaldat &amp;nbsp;; *** need to append the "outdat" from %getdata each, so the 100 "outdat" are appended to "finaldat";&lt;/P&gt;
&lt;P&gt;%mend app;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 11 Jun 2017 19:32:29 GMT</pubDate>
    <dc:creator>jojo</dc:creator>
    <dc:date>2017-06-11T19:32:29Z</dc:date>
    <item>
      <title>appending data in iteration</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/appending-data-in-iteration/m-p/366005#M11034</link>
      <description>&lt;P&gt;Hi I want to append output data from a macro and repeat this process 100 times, how to implement this in SAS? Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro app(n=);&lt;/P&gt;
&lt;P&gt;%do i =1 %to &amp;amp;n;&lt;/P&gt;
&lt;P&gt;%getdata(a=,b=,c=); **** get "outdat" here for each i;&lt;/P&gt;
&lt;P&gt;Proc append base=outdat data=finaldat &amp;nbsp;; *** need to append the "outdat" from %getdata each, so the 100 "outdat" are appended to "finaldat";&lt;/P&gt;
&lt;P&gt;%mend app;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Jun 2017 19:32:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/appending-data-in-iteration/m-p/366005#M11034</guid>
      <dc:creator>jojo</dc:creator>
      <dc:date>2017-06-11T19:32:29Z</dc:date>
    </item>
    <item>
      <title>Re: appending data in iteration</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/appending-data-in-iteration/m-p/366006#M11035</link>
      <description>&lt;P&gt;If you want to append outdat to finaldat, you need to use base=finaldat data=outdat in the proc append statement.&lt;/P&gt;</description>
      <pubDate>Sun, 11 Jun 2017 19:37:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/appending-data-in-iteration/m-p/366006#M11035</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-06-11T19:37:14Z</dc:date>
    </item>
    <item>
      <title>Re: appending data in iteration</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/appending-data-in-iteration/m-p/366008#M11036</link>
      <description>&lt;P&gt;Why not include Append in macro directly?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Jun 2017 21:18:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/appending-data-in-iteration/m-p/366008#M11036</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-11T21:18:30Z</dc:date>
    </item>
    <item>
      <title>Re: appending data in iteration</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/appending-data-in-iteration/m-p/366013#M11038</link>
      <description>&lt;P&gt;You're relatively close, as indicated you need some small changes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Add a drop table at beginning of process to remove master table first. If you have a specific structure requried that may not be maintained in process, ie variable lengths/formats you could make a master table with the structure desired but empty.&lt;/P&gt;
&lt;P&gt;2. Switch names in Append as indicated by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;3. Add a drop table for your generated data. You don't want to accidentally duplicate appending the results somehow.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4. Missing %END for your %DO.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro app(n=);

*drop master table before loops in case of re-runs, optional;
proc sql noprint;
    drop table finaldat;
quit;

%do i =1 %to &amp;amp;n;

%getdata(a=,b=,c=); **** get "outdat" here for each i;

Proc append base=finaldat data=outdat ;
run;

*remove dataset so that you do not accidentally append multiple times;
proc sql noprint;
   drop table outdat;
quit; 

%end; *missed this for the end of your loop;

%mend app;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 11 Jun 2017 23:27:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/appending-data-in-iteration/m-p/366013#M11038</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-11T23:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: appending data in iteration</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/appending-data-in-iteration/m-p/366027#M11039</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30380"&gt;@jojo&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Proposed&amp;nbsp;small change to the code&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;posted:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of a Proc SQL DROP...&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
    drop table finaldat;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;...use a Proc DATASETS DELETE with option NOWARN&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets lib=WORK nolist nowarn;
  delete finaldat;
  run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Reason:&lt;/P&gt;
&lt;P&gt;Proc SQL DROP will throw an ERROR in case table &lt;EM&gt;FINALDAT&lt;/EM&gt;&amp;nbsp;doesn't exists - which is likely the case the first time you run your macro.&lt;/P&gt;
&lt;P&gt;Proc DATASETS with option NOWARN on the other hand will deal nicely with cases where there isn't a table to be deleted.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jun 2017 00:58:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/appending-data-in-iteration/m-p/366027#M11039</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-06-12T00:58:06Z</dc:date>
    </item>
    <item>
      <title>Re: appending data in iteration</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/appending-data-in-iteration/m-p/366158#M11043</link>
      <description>&lt;P&gt;Note that if your data sets you want to combine have a common and unique start to their name you may not need this at all to combine your data sets as you can use a name list. Suppose all of the data sets you want start with the PDQ.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data finaldata;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set PDQ:&amp;nbsp; ;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note the colon, that says to use all the sets that start with PDQ. So PDQ101 PDQabc and PDQ___57 would all be combined.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jun 2017 14:16:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/appending-data-in-iteration/m-p/366158#M11043</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-06-12T14:16:45Z</dc:date>
    </item>
    <item>
      <title>Re: appending data in iteration</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/appending-data-in-iteration/m-p/366652#M11055</link>
      <description>&lt;P&gt;Thanks very much, Reeza. For some reason, my final data has only one record when I ran the app with n&amp;gt;=1. Any suggestions?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2017 15:46:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/appending-data-in-iteration/m-p/366652#M11055</guid>
      <dc:creator>jojo</dc:creator>
      <dc:date>2017-06-13T15:46:47Z</dc:date>
    </item>
    <item>
      <title>Re: appending data in iteration</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/appending-data-in-iteration/m-p/366653#M11056</link>
      <description>&lt;P&gt;Thanks, changed to proc datasets delete&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2017 15:47:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/appending-data-in-iteration/m-p/366653#M11056</guid>
      <dc:creator>jojo</dc:creator>
      <dc:date>2017-06-13T15:47:57Z</dc:date>
    </item>
    <item>
      <title>Re: appending data in iteration</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/appending-data-in-iteration/m-p/366701#M11059</link>
      <description>&lt;P&gt;Thanks all. I found the error and fixed the program (the i was used in the macro and was greater to &amp;amp;n).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2017 17:51:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/appending-data-in-iteration/m-p/366701#M11059</guid>
      <dc:creator>jojo</dc:creator>
      <dc:date>2017-06-13T17:51:07Z</dc:date>
    </item>
  </channel>
</rss>

