<?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 in a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-in-a-macro/m-p/395994#M278084</link>
    <description>&lt;P&gt;Sorry if my message was not clear enough.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Are you trying to add a year variable to multiple data sets based on their folder or name of the file? &lt;STRONG&gt;Yes&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;And you need to do it multiple times for multiple folders?&lt;STRONG&gt; yes&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the code that works for one year-file (2002 file):&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Libname data02 'P:\2002';&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%macro year_2002(dn);&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data data02.&amp;amp;dn;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;set data02.&amp;amp;dn;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;year=2002;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;% mend year_2002;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc contents data=data02._all_ noprint out=contents;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data _null_;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;set contents;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;by memname;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;call execute (cats('%year_2002(',memname,')'));&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It adds the variable year=2002 to every dataset contained in file 2002.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a naming convention that helps to define the folders/year?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Yes my folders are called: DADS Postes 1998; DADS Postes 1999; DADS Postes 2000 etc until 2010; so there is a repeting convention on the name of the files.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="lia-quilt-row lia-quilt-row-forum-message-main"&gt;&lt;DIV class="lia-quilt-column lia-quilt-column-20 lia-quilt-column-right lia-quilt-column-main-right"&gt;&lt;DIV class="lia-quilt-column-alley lia-quilt-column-alley-right"&gt;&lt;DIV class="lia-message-body lia-component-body"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;Are you planning to combine these at some point?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will append files contained in each year file (all regions for 2002, all regions for 2003 etc) but even if I do this before, i do not know how to create the variable year for all files if year is not equal in all files.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much, I hope I made things clearer !&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Eugenie&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="lia-quilt-row lia-quilt-row-forum-message-footer"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
    <pubDate>Thu, 14 Sep 2017 15:54:00 GMT</pubDate>
    <dc:creator>eugenia67</dc:creator>
    <dc:date>2017-09-14T15:54:00Z</dc:date>
    <item>
      <title>Macro in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-in-a-macro/m-p/395962#M278081</link>
      <description>&lt;P&gt;Hi everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have 13 files per year, one file per year (from year 1998 to year 2010). Each file contains 22 datasets. (in each year-file, i have 22 datasets corresponding to one data set&amp;nbsp;per region, I have 22 region).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the 22 datasets of each year file i want to create a variable year equal to the year of each data set.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I put two pictures to give an example of what I want:&amp;nbsp;&lt;/P&gt;&lt;P&gt;the first picture shows the year file and the second shows what contains the file for year 1998.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I've done until now is create a macro for each different year, but I though maybe there is a way to put a macro in a macro in order to avoid copying pasting the code 13 times for each year.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope you can help me on that!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Eugéni&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Year files" style="width: 450px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/15154i1E7D363539CF87F3/image-size/large?v=v2&amp;amp;px=999" role="button" title="SAS1.jpg" alt="Year files" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Year files&lt;/span&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Datasets in a year file" style="width: 450px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/15156iF8A5441BFD599A4A/image-size/large?v=v2&amp;amp;px=999" role="button" title="SAS2.jpg" alt="Datasets in a year file" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Datasets in a year file&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 15:15:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-in-a-macro/m-p/395962#M278081</guid>
      <dc:creator>eugenia67</dc:creator>
      <dc:date>2017-09-14T15:15:27Z</dc:date>
    </item>
    <item>
      <title>Re: Macro in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-in-a-macro/m-p/395985#M278082</link>
      <description>&lt;P&gt;Pictures are not very helpful.&lt;/P&gt;
&lt;P&gt;As for your question, without seeing some code its hard to say, but say I have:&lt;/P&gt;
&lt;PRE&gt;%macro Add_Var (lib,ds=);
  data &amp;amp;lib..&amp;amp;ds.;
    set &amp;amp;lib..&amp;amp;ds.;
    new_var=1;
  run;
%mend Add_Var;
 
/* Now I use Base SAS to call that macro over and over */
data _null_;
  do yr=1998 to 2010;
    do reg="ABC","DEF";
      call execute(cats('%Add_Var (lib=',put(yr,4.),',ds=',reg,');'));
    end;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;Now the real question here however is why do you have all your data split up into little bits. &amp;nbsp;It is never a good idea, and will make all your programming much harder. &amp;nbsp;Put it all together in one dataset with a variable for year, and variable for region, and your coding will be simpler and faster as you will use by groups.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 15:41:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-in-a-macro/m-p/395985#M278082</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-09-14T15:41:19Z</dc:date>
    </item>
    <item>
      <title>Re: Macro in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-in-a-macro/m-p/395990#M278083</link>
      <description>&lt;P&gt;This clear as mud.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you trying to add a year variable to multiple data sets based on their folder or name of the file?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And you need to do it multiple times for multiple folders?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have code that works for one?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a naming convention that helps to define the folders/year?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you planning to combine these at some point?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 15:44:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-in-a-macro/m-p/395990#M278083</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-14T15:44:57Z</dc:date>
    </item>
    <item>
      <title>Re: Macro in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-in-a-macro/m-p/395994#M278084</link>
      <description>&lt;P&gt;Sorry if my message was not clear enough.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Are you trying to add a year variable to multiple data sets based on their folder or name of the file? &lt;STRONG&gt;Yes&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;And you need to do it multiple times for multiple folders?&lt;STRONG&gt; yes&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is the code that works for one year-file (2002 file):&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Libname data02 'P:\2002';&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;%macro year_2002(dn);&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data data02.&amp;amp;dn;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;set data02.&amp;amp;dn;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;year=2002;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;% mend year_2002;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc contents data=data02._all_ noprint out=contents;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data _null_;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;set contents;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;by memname;&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;call execute (cats('%year_2002(',memname,')'));&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It adds the variable year=2002 to every dataset contained in file 2002.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a naming convention that helps to define the folders/year?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Yes my folders are called: DADS Postes 1998; DADS Postes 1999; DADS Postes 2000 etc until 2010; so there is a repeting convention on the name of the files.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="lia-quilt-row lia-quilt-row-forum-message-main"&gt;&lt;DIV class="lia-quilt-column lia-quilt-column-20 lia-quilt-column-right lia-quilt-column-main-right"&gt;&lt;DIV class="lia-quilt-column-alley lia-quilt-column-alley-right"&gt;&lt;DIV class="lia-message-body lia-component-body"&gt;&lt;DIV class="lia-message-body-content"&gt;&lt;P&gt;Are you planning to combine these at some point?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I will append files contained in each year file (all regions for 2002, all regions for 2003 etc) but even if I do this before, i do not know how to create the variable year for all files if year is not equal in all files.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much, I hope I made things clearer !&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Eugenie&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="lia-quilt-row lia-quilt-row-forum-message-footer"&gt;&amp;nbsp;&lt;/DIV&gt;</description>
      <pubDate>Thu, 14 Sep 2017 15:54:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-in-a-macro/m-p/395994#M278084</guid>
      <dc:creator>eugenia67</dc:creator>
      <dc:date>2017-09-14T15:54:00Z</dc:date>
    </item>
    <item>
      <title>Re: Macro in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-in-a-macro/m-p/395997#M278085</link>
      <description>&lt;P&gt;You might be able to leave your files along and use the INDSNAME= option on the INFILE statement to get at the dataset/folder name.&lt;/P&gt;
&lt;P&gt;For example you could create separated libnames for each folder.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;libname DADS1998 'DADS Postes 1998';
libname DADS1999 'DADS Postes 1999';
libname DADS2000 'DADS Postes 2000';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then if each libref has a member named MYDATA you could make a temporary dataset that combines three years into one dataset.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mydata ;
  length dsn $41 year 8;
  set dads1998.mydata dads1999.mydata dads2000.mydata indsname=dsn;
  year = input(substr(dsn,5),4.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could skip the librefs and just reference the datasets by filename. &amp;nbsp;Make the variable that you use with INDSNAME longer.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mydata ;
  length dsn $256 year 8;
  set 
    'DADS Postes 1998/mydata'
    'DADS Postes 1999/mydata'
    'DADS Postes 2000/mydata'
    indsname=dsn
  ;
  year = input(scan(scan(dsn,-2,'/\'),-1,' '),4.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Sep 2017 16:07:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-in-a-macro/m-p/395997#M278085</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-09-14T16:07:55Z</dc:date>
    </item>
    <item>
      <title>Re: Macro in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-in-a-macro/m-p/395998#M278086</link>
      <description>&lt;P&gt;Ok, a bit clearer now. &amp;nbsp;Right so something like;&lt;/P&gt;
&lt;PRE&gt;data _null_;
  do yr=1998 to 2010;
    call execute(cats('libname tmp "c:\pathtofiles\DADS Postes ',put(yr,4.),'";'));
    call execute(cats('data total',put(yr,4.),'; set post: indsname=tmp; year=substr(tmp,5,); run;'));&lt;BR /&gt;    call execute('libname tmp clear;');&lt;BR /&gt;  end;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data final;&lt;BR /&gt;  set total:;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;The first loop creates code which creates a libname to the year, combines all the datasets with prefix "post" - from your screenshot - into one bg dataset for the year called total&amp;lt;year&amp;gt;. &amp;nbsp;Then clears the libname and loops round for the next year. &amp;nbsp;Once all that is done then the final datastep puts all the total&amp;lt;year&amp;gt; datasets together in on final dataset. &amp;nbsp;Note this assumes all the files have the same structure.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 16:11:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-in-a-macro/m-p/395998#M278086</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-09-14T16:11:00Z</dc:date>
    </item>
    <item>
      <title>Re: Macro in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-in-a-macro/m-p/395999#M278087</link>
      <description>&lt;P&gt;Assumptions:&lt;/P&gt;
&lt;P&gt;You have 13 folders.&lt;/P&gt;
&lt;P&gt;Each folder has 22 datasets for a specific region&lt;/P&gt;
&lt;P&gt;You want to combine all the datasets in the folder into one data set per year, with a variable for year and region name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's some untested code as a sample. It apends the&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro append_data(path, year);

libname myfiles "&amp;amp;path";&lt;BR /&gt;&lt;BR /&gt;data year&amp;amp;year.;&lt;BR /&gt;length source region $50.;&lt;BR /&gt;set post: indsname = source;&lt;BR /&gt;region = source;&lt;BR /&gt;year= &amp;amp;year;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;libname myfiles;&lt;BR /&gt;&lt;BR /&gt;%mend;
&lt;BR /&gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And then call it 13 times:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%append_data(P:\2002\, 2002);
%append_data(P:\2003\, 2003);
....


...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can make it more dynamic if you want using a data step and CALL EXECUTE to call the macro.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'll leave that as an exercise for you, with the &amp;nbsp;note that CALL EXECUTE documentation has a good example of implementing this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 16:11:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-in-a-macro/m-p/395999#M278087</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-14T16:11:58Z</dc:date>
    </item>
    <item>
      <title>Re: Macro in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-in-a-macro/m-p/396246#M278088</link>
      <description>&lt;P&gt;Thank you for your answer!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I understand the logic, nevertheless it does not work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error message appears at this point:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt; call execute(cats('data total',put(yr,4.),'; set post: indsname=tmp; year=substr(tmp,5,); run;'));&lt;/PRE&gt;&lt;P&gt;It says:&lt;STRONG&gt; " the data set list (work.post:) does not contain any member"&lt;/STRONG&gt;. That means maybe that the library tmp was not correctly created so it can not find the datasets beginning by "post"?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It creates 14 datafiles total1998, total1999 etc but they are all empty, with 0 observations&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2017 10:41:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-in-a-macro/m-p/396246#M278088</guid>
      <dc:creator>eugenia67</dc:creator>
      <dc:date>2017-09-15T10:41:58Z</dc:date>
    </item>
    <item>
      <title>Re: Macro in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-in-a-macro/m-p/396358#M278089</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/156094"&gt;@eugenia67&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thank you for your answer!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I understand the logic, nevertheless it does not work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The error message appears at this point:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt; call execute(cats('data total',put(yr,4.),'; set post: indsname=tmp; year=substr(tmp,5,); run;'));&lt;/PRE&gt;
&lt;P&gt;It says:&lt;STRONG&gt; " the data set list (work.post:) does not contain any member"&lt;/STRONG&gt;. That means maybe that the library tmp was not correctly created so it can not find the datasets beginning by "post"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It creates 14 datafiles total1998, total1999 etc but they are all empty, with 0 observations&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You need to adapt the code. In this case it was designed to work off the work library. Change it so it uses your libname reference from the previous line. See the modified code below and the addition of tmp. in front of the data set name post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data _null_;
  do yr=1998 to 2010;
    call execute(cats('libname tmp "c:\pathtofiles\DADS Postes ',put(yr,4.),'";'));
    call execute(cats('data total',put(yr,4.),'; set tmp.post: indsname=tmp; year=substr(tmp,5,); run;'));&lt;BR /&gt;    call execute('libname tmp clear;');&lt;BR /&gt;  end;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data final;&lt;BR /&gt;  set total:;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2017 14:45:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-in-a-macro/m-p/396358#M278089</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-15T14:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: Macro in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-in-a-macro/m-p/396402#M278090</link>
      <description>&lt;P&gt;I did put tmp.postes&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actually it was not working because&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;"c:\pathtofiles\DADS Postes ',put(yr,4.),'";'));&lt;/PRE&gt;&lt;P&gt;the program was not recognizing DADS postes 1998 because of the space between postes and 1998. I removed the space in the datafile and it worked!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2017 15:40:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-in-a-macro/m-p/396402#M278090</guid>
      <dc:creator>eugenia67</dc:creator>
      <dc:date>2017-09-15T15:40:28Z</dc:date>
    </item>
    <item>
      <title>Re: Macro in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-in-a-macro/m-p/396404#M278091</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/156094"&gt;@eugenia67&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I did put tmp.postes&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Not in the code you posted and that's all we can see.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2017 15:42:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-in-a-macro/m-p/396404#M278091</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-15T15:42:32Z</dc:date>
    </item>
  </channel>
</rss>

