<?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: SAS macro to append multiple data sets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to-append-multiple-data-sets/m-p/921997#M363089</link>
    <description>&lt;P&gt;You have had a few suggestions of various ways to simplify your code using wildcards etc. - but if you need to do the append with a specific number of increasing dates, your own method may be the right way to do it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem you have with the BASEMON&amp;amp;count variable is, as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;remarked, that you put the macro variable name in single quotes, like&amp;nbsp;&lt;SPAN&gt;'BASEMON&amp;amp;COUNT', this means the data step will try to put data into a macro variable named BASEMON&amp;amp;COUNT and not e.g. BASEMON1 (no resolution of the COUNT variable, so the macro variable name will not be syntactically correct).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;But I would probably write the macro somewhat differently, a first version would look like this:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO JOIN; 
%local StartMonth NoofMonths OutData Date Month DD_Month;
%LET StartMonth = 202202; /* a better and more descriptive name than DD */
%let NoofMonths=5; /* we do 1 to 5 and not 0 to 4, is intuitively easier */
%let OutData=TEST;
/* now convert StartMonth to e.g. 01FEB2022 */
%let Date=%sysfunc(input(&amp;amp;StartMonth,YYMMN6.),date9.);

/* Delete output, if exists */
Proc delete data=&amp;amp;outdata;run;

/* and then we loop, proc APPEND will create a new table if BASE does not exist */
%do Month=1 %to &amp;amp;NoofMonths;
  %let DD_Month=%sysfunc(put("&amp;amp;Date"d,YYMMN6.));
  PROC APPEND BASE =&amp;amp;outdata DATA=DATA_SET_&amp;amp;DD_Month;
  RUN;
  %let Date=%sysfunc(intnx(MONTH,"&amp;amp;Date"d,1,B),date9.);
  %end;

%MEND; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;You could also make the DATE macro variable a numeric variable, but I prefer using the DATE9. format, which makes SYMBOLGEN output much easier to understand.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;When running for real, you will want to use parameters for your macro, e.g.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO JOIN(StartMonth,NoofMonths,OutData); 
%local Date Month DD_Month;
/* now convert StartMonth to e.g. 01FEB2022 */
%let Date=%sysfunc(input(&amp;amp;StartMonth,YYMMN6.),date9.);

/* Delete output, if exists */
Proc delete data=&amp;amp;outdata;run;

/* and then we loop, proc APPEND will create a new table if BASE does not exist */
%do Month=1 %to &amp;amp;NoofMonths;
  %let DD_Month=%sysfunc(put("&amp;amp;Date"d,YYMMN6.));
  PROC APPEND BASE =&amp;amp;outdata DATA=DATA_SET_&amp;amp;DD_Month;
  RUN;
  %let Date=%sysfunc(intnx(MONTH,"&amp;amp;Date"d,1),date9.);
  %end;

%MEND; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;So you can call it like&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%join(202202,5,TEST);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Mar 2024 16:20:41 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2024-03-27T16:20:41Z</dc:date>
    <item>
      <title>SAS macro to append multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to-append-multiple-data-sets/m-p/921946#M363072</link>
      <description>&lt;P&gt;Hi I have data sets as follows :&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA_SET_202202 (Records for month Feb, 2022)&lt;/P&gt;&lt;P&gt;DATA_SET_202203 (Records for month Mar, 2022)&amp;nbsp;&lt;/P&gt;&lt;P&gt;and so on&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to append all the data sets in a single table such that records from DATA_SET_202202 are first followed by _202203&amp;nbsp;&lt;/P&gt;&lt;P&gt;and so on&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using the below MACRO for this&amp;nbsp; :&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%MACRO JOIN;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%LET DD = '202202';&lt;/P&gt;&lt;P&gt;%DO COUNT = 0 %TO 4 ;&amp;nbsp; /*FOR TEST RUN*/&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%LET DD_DATE = INPUT(&amp;amp;DD.,YYMMN6.);&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA _NULL_ ;&lt;/P&gt;&lt;P&gt;CALL SYMPUTX('BASEMON&amp;amp;COUNT', PUT(INTNX('MONTH',&amp;amp;DD_DATE.,&amp;amp;COUNT.),YYMMN6.));&lt;/P&gt;&lt;P&gt;RUN;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%PUT BASEMON&amp;amp;COUNT:&amp;amp;&amp;amp;BASEMON&amp;amp;COUNT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%IF &amp;amp;COUNT. = 0 %THEN %DO ;&lt;/P&gt;&lt;P&gt;DATA TEST;&lt;/P&gt;&lt;P&gt;SET&amp;nbsp;DATA_SET_&amp;amp;&amp;amp;BASEMON&amp;amp;COUNT.;&lt;/P&gt;&lt;P&gt;RUN;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%END;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%ELSE %D0;&lt;/P&gt;&lt;P&gt;PROC APPEND BASE =TEST DATA=DATA_SET_&amp;amp;&amp;amp;BASEMON&amp;amp;COUNT.;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;%END;&lt;/P&gt;&lt;P&gt;%END;&lt;/P&gt;&lt;P&gt;%MEND;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this i am getting error that my variable basemon&amp;amp;count itself is not getting created. Can anyone please suggest&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 11:34:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to-append-multiple-data-sets/m-p/921946#M363072</guid>
      <dc:creator>ajatshatru</dc:creator>
      <dc:date>2024-03-27T11:34:18Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro to append multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to-append-multiple-data-sets/m-p/921953#M363073</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;'BASEMON&amp;amp;COUNT'&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The most important function of single quotes: they prevent the resolution of macro triggers. Use double quotes.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 12:09:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to-append-multiple-data-sets/m-p/921953#M363073</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2024-03-27T12:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro to append multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to-append-multiple-data-sets/m-p/921956#M363074</link>
      <description>&lt;P&gt;Why a macro at all?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why not this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want; 
    set data_set_2022: ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Mar 2024 12:15:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to-append-multiple-data-sets/m-p/921956#M363074</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-03-27T12:15:35Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro to append multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to-append-multiple-data-sets/m-p/921985#M363081</link>
      <description>&lt;P&gt;Instead of listing them manually use shortcut lists.&lt;/P&gt;
&lt;P&gt;Here is a reference that illustrates how to refer to variables and datasets in a short cut list:&lt;BR /&gt;&lt;A href="https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2018/05/29/6-easy-ways-to-specify-a-list-of-variables-in-sas.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Additionally you can use INDSNAME option to store the source data set name and then sort by that variable if you want a specific order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
length source dsn $32.;
set data_set_2022: indsname=source; *will append any datasets that start with the prefix;
dsn = source;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/463954"&gt;@ajatshatru&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi I have data sets as follows :&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA_SET_202202 (Records for month Feb, 2022)&lt;/P&gt;
&lt;P&gt;DATA_SET_202203 (Records for month Mar, 2022)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and so on&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to append all the data sets in a single table such that records from DATA_SET_202202 are first followed by _202203&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and so on&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using the below MACRO for this&amp;nbsp; :&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%MACRO JOIN;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%LET DD = '202202';&lt;/P&gt;
&lt;P&gt;%DO COUNT = 0 %TO 4 ;&amp;nbsp; /*FOR TEST RUN*/&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%LET DD_DATE = INPUT(&amp;amp;DD.,YYMMN6.);&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;DATA _NULL_ ;&lt;/P&gt;
&lt;P&gt;CALL SYMPUTX('BASEMON&amp;amp;COUNT', PUT(INTNX('MONTH',&amp;amp;DD_DATE.,&amp;amp;COUNT.),YYMMN6.));&lt;/P&gt;
&lt;P&gt;RUN;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%PUT BASEMON&amp;amp;COUNT:&amp;amp;&amp;amp;BASEMON&amp;amp;COUNT;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%IF &amp;amp;COUNT. = 0 %THEN %DO ;&lt;/P&gt;
&lt;P&gt;DATA TEST;&lt;/P&gt;
&lt;P&gt;SET&amp;nbsp;DATA_SET_&amp;amp;&amp;amp;BASEMON&amp;amp;COUNT.;&lt;/P&gt;
&lt;P&gt;RUN;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%END;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%ELSE %D0;&lt;/P&gt;
&lt;P&gt;PROC APPEND BASE =TEST DATA=DATA_SET_&amp;amp;&amp;amp;BASEMON&amp;amp;COUNT.;&lt;/P&gt;
&lt;P&gt;RUN;&lt;/P&gt;
&lt;P&gt;%END;&lt;/P&gt;
&lt;P&gt;%END;&lt;/P&gt;
&lt;P&gt;%MEND;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this i am getting error that my variable basemon&amp;amp;count itself is not getting created. Can anyone please suggest&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 15:12:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to-append-multiple-data-sets/m-p/921985#M363081</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2024-03-27T15:12:26Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro to append multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to-append-multiple-data-sets/m-p/921986#M363082</link>
      <description>&lt;P&gt;Depending on your actual needs you might look at using dataset lists.&lt;/P&gt;
&lt;P&gt;You can use prefix based lists by using a colon.&amp;nbsp; So if you want to combine any dataset from 2022 it might look like this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  set DATA_SET_2022: ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you can use numeric sequences using hyphen.&amp;nbsp; So if you want March 2022 to August 2023 you might use this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  set DATA_SET_202203 - DATA_SET_202212 DATA_SET_202301 - DATA_SET_202308 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could make your macro simpler by just generating the list of dataset names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dslist(prefix,start,end);
%local offset;
%do offset=0 %to %sysfunc(intck(month,&amp;amp;start,&amp;amp;end));
 &amp;amp;prefix.%sysfunc(intnx(month,&amp;amp;start,&amp;amp;offset),yymmn6.)
%end;
%mend dslist;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;so that you could call it in the middle of a statement, like the SET statement.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  set %dslist(data_set_,'01SEP2022'd,'01MAR2023'd) ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 15:26:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to-append-multiple-data-sets/m-p/921986#M363082</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-03-27T15:26:19Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro to append multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to-append-multiple-data-sets/m-p/921992#M363085</link>
      <description>&lt;P&gt;You could even use the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lesysoptsref/p1o6bsb5wep7ahn1f8mlw3jf2drq.htm" target="_blank" rel="noopener"&gt;NODSNFERR system option&lt;/A&gt; in conjunction with a dataset list spanning several years:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options nodsnferr;

data test;
set data_set_202202-data_set_202403;
run;

options dsnferr;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Mar 2024 15:50:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to-append-multiple-data-sets/m-p/921992#M363085</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-03-27T15:50:51Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro to append multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to-append-multiple-data-sets/m-p/921993#M363086</link>
      <description>&lt;P&gt;I would add one more "option":&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options nodsnferr;

data test;
  set data_set_: INDSNAME=inds;
  obsFromDataSet=inds;
  dataPeriod = input(scan(inds,-1,"_"),yymmdd10.);
  format dataPeriod yymmdd10.;
run;

options dsnferr;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The INDSNAME= gets you info about dataset from which a given observation is from.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 15:56:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to-append-multiple-data-sets/m-p/921993#M363086</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-03-27T15:56:03Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro to append multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to-append-multiple-data-sets/m-p/921997#M363089</link>
      <description>&lt;P&gt;You have had a few suggestions of various ways to simplify your code using wildcards etc. - but if you need to do the append with a specific number of increasing dates, your own method may be the right way to do it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The problem you have with the BASEMON&amp;amp;count variable is, as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;remarked, that you put the macro variable name in single quotes, like&amp;nbsp;&lt;SPAN&gt;'BASEMON&amp;amp;COUNT', this means the data step will try to put data into a macro variable named BASEMON&amp;amp;COUNT and not e.g. BASEMON1 (no resolution of the COUNT variable, so the macro variable name will not be syntactically correct).&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;But I would probably write the macro somewhat differently, a first version would look like this:&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO JOIN; 
%local StartMonth NoofMonths OutData Date Month DD_Month;
%LET StartMonth = 202202; /* a better and more descriptive name than DD */
%let NoofMonths=5; /* we do 1 to 5 and not 0 to 4, is intuitively easier */
%let OutData=TEST;
/* now convert StartMonth to e.g. 01FEB2022 */
%let Date=%sysfunc(input(&amp;amp;StartMonth,YYMMN6.),date9.);

/* Delete output, if exists */
Proc delete data=&amp;amp;outdata;run;

/* and then we loop, proc APPEND will create a new table if BASE does not exist */
%do Month=1 %to &amp;amp;NoofMonths;
  %let DD_Month=%sysfunc(put("&amp;amp;Date"d,YYMMN6.));
  PROC APPEND BASE =&amp;amp;outdata DATA=DATA_SET_&amp;amp;DD_Month;
  RUN;
  %let Date=%sysfunc(intnx(MONTH,"&amp;amp;Date"d,1,B),date9.);
  %end;

%MEND; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;You could also make the DATE macro variable a numeric variable, but I prefer using the DATE9. format, which makes SYMBOLGEN output much easier to understand.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;When running for real, you will want to use parameters for your macro, e.g.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%MACRO JOIN(StartMonth,NoofMonths,OutData); 
%local Date Month DD_Month;
/* now convert StartMonth to e.g. 01FEB2022 */
%let Date=%sysfunc(input(&amp;amp;StartMonth,YYMMN6.),date9.);

/* Delete output, if exists */
Proc delete data=&amp;amp;outdata;run;

/* and then we loop, proc APPEND will create a new table if BASE does not exist */
%do Month=1 %to &amp;amp;NoofMonths;
  %let DD_Month=%sysfunc(put("&amp;amp;Date"d,YYMMN6.));
  PROC APPEND BASE =&amp;amp;outdata DATA=DATA_SET_&amp;amp;DD_Month;
  RUN;
  %let Date=%sysfunc(intnx(MONTH,"&amp;amp;Date"d,1),date9.);
  %end;

%MEND; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;So you can call it like&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%join(202202,5,TEST);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 16:20:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to-append-multiple-data-sets/m-p/921997#M363089</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2024-03-27T16:20:41Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro to append multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to-append-multiple-data-sets/m-p/922000#M363091</link>
      <description>&lt;P&gt;&amp;nbsp;I do not have just a single data_set_2022. I have many monthly tables like this which i need to append in a single data set. So i am using a macro and a loop&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 16:45:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to-append-multiple-data-sets/m-p/922000#M363091</guid>
      <dc:creator>ajatshatru</dc:creator>
      <dc:date>2024-03-27T16:45:14Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro to append multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to-append-multiple-data-sets/m-p/922001#M363092</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/463954"&gt;@ajatshatru&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;I do not have just a single data_set_2022. I have many monthly tables like this which i need to append in a single data set. So i am using a macro and a loop&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It was obvious from your question that you had multiple datasets.&amp;nbsp; None of the answered submitted so far assumed otherwise.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 16:50:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to-append-multiple-data-sets/m-p/922001#M363092</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-03-27T16:50:35Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro to append multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to-append-multiple-data-sets/m-p/922002#M363093</link>
      <description>&lt;P&gt;Read this:&amp;nbsp;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p00hxg3x8lwivcn1f0e9axziw57y.htm#p02h8j6i59drj1n1l5449rfd9jbq" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lestmtsref/p00hxg3x8lwivcn1f0e9axziw57y.htm#p02h8j6i59drj1n1l5449rfd9jbq&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;so you will understand that this is what you need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 16:53:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to-append-multiple-data-sets/m-p/922002#M363093</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-03-27T16:53:30Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro to append multiple data sets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to-append-multiple-data-sets/m-p/922006#M363096</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/463954"&gt;@ajatshatru&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;I do not have just a single data_set_2022. I have many monthly tables like this which i need to append in a single data set. So i am using a macro and a loop&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I did not write code for the case where you had a single data set. The code I wrote appends all data sets whose name BEGINS WITH data_set_2022.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Mar 2024 17:13:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-to-append-multiple-data-sets/m-p/922006#M363096</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-03-27T17:13:21Z</dc:date>
    </item>
  </channel>
</rss>

