<?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 question in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Macro-question/m-p/1227#M569</link>
    <description>&lt;B&gt;Well, still can't get it to work...the Enlhist9 is a library that is automatically assigned with my AutoEx? If that helps?&lt;/B&gt; FYI - I changed dt to i.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
84   %macro names(lib,year,maxnum);&lt;BR /&gt;
85           %do i=1 %to &amp;amp;maxnum;&lt;BR /&gt;
86           &amp;amp;lib&amp;amp;year%sysfunc(putn(&amp;amp;i, z2.));&lt;BR /&gt;
87           %end;&lt;BR /&gt;
88   %mend names;&lt;BR /&gt;
&lt;BR /&gt;
89   data all;&lt;BR /&gt;
90     set %names(Enlhist9.Aae,2001,5);&lt;BR /&gt;
SYMBOLGEN:  Macro variable MAXNUM resolves to 5&lt;BR /&gt;
SYMBOLGEN:  Macro variable LIB resolves to Enlhist9.Aae&lt;BR /&gt;
SYMBOLGEN:  Macro variable YEAR resolves to 2001&lt;BR /&gt;
SYMBOLGEN:  Macro variable I resolves to 1&lt;BR /&gt;
MPRINT(NAMES):   Enlhist9.Aae200101;&lt;BR /&gt;
SYMBOLGEN:  Macro variable LIB resolves to Enlhist9.Aae&lt;BR /&gt;
SYMBOLGEN:  Macro variable YEAR resolves to 2001&lt;BR /&gt;
SYMBOLGEN:  Macro variable I resolves to 2&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.21 seconds&lt;BR /&gt;
      cpu time            0.00 seconds&lt;BR /&gt;
&lt;BR /&gt;
ERROR: DATA STEP Component Object failure.  Aborted during the COMPILATION phase.&lt;BR /&gt;
NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;
MPRINT(NAMES):   Enlhist9.Aae200102;&lt;BR /&gt;
SYMBOLGEN:  Macro variable LIB resolves to Enlhist9.Aae&lt;BR /&gt;
SYMBOLGEN:  Macro variable YEAR resolves to 2001&lt;BR /&gt;
SYMBOLGEN:  Macro variable I resolves to 3&lt;BR /&gt;
NOTE: Line generated by the macro function "SYSFUNC".&lt;BR /&gt;
1             Enlhist9.Aae200102&lt;BR /&gt;
              ------------------&lt;BR /&gt;
              557&lt;BR /&gt;
MPRINT(NAMES):   Enlhist9.Aae200103;&lt;BR /&gt;
SYMBOLGEN:  Macro variable LIB resolves to Enlhist9.Aae&lt;BR /&gt;
SYMBOLGEN:  Macro variable YEAR resolves to 2001&lt;BR /&gt;
SYMBOLGEN:  Macro variable I resolves to 4&lt;BR /&gt;
MPRINT(NAMES):   Enlhist9.Aae200104;&lt;BR /&gt;
SYMBOLGEN:  Macro variable LIB resolves to Enlhist9.Aae&lt;BR /&gt;
SYMBOLGEN:  Macro variable YEAR resolves to 2001&lt;BR /&gt;
SYMBOLGEN:  Macro variable I resolves to 5&lt;BR /&gt;
MPRINT(NAMES):   Enlhist9.Aae200105;&lt;BR /&gt;
ERROR 557-185: Variable Enlhist9 is not an object.&lt;BR /&gt;
&lt;BR /&gt;
91   run;</description>
    <pubDate>Wed, 09 Aug 2006 17:53:14 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2006-08-09T17:53:14Z</dc:date>
    <item>
      <title>Macro question</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Macro-question/m-p/1225#M567</link>
      <description>Not sure if this is the right forum for this, but here goes:&lt;BR /&gt;
&lt;BR /&gt;
I want to be able to build one data set with multiple data sets without having to write multiple set statements.  The datasets are in a specific library and in the format example: hist9.aae200601&lt;BR /&gt;
&lt;BR /&gt;
With the last 2 characters representing the month (01=January, 02=February, etc, etc).&lt;BR /&gt;
&lt;BR /&gt;
&lt;U&gt;Here is the code I have started with:&lt;/U&gt;&lt;BR /&gt;
&lt;BR /&gt;
%macro names(lib,year,maxnum);&lt;BR /&gt;
  		%do dt=1 %to &amp;amp;maxnum;&lt;BR /&gt;
    	&amp;amp;lib&amp;amp;year&amp;amp;i;&lt;BR /&gt;
 		%end;&lt;BR /&gt;
  ;&lt;BR /&gt;
%mend names;&lt;BR /&gt;
&lt;BR /&gt;
/* Call the macro on the SET statement */&lt;BR /&gt;
&lt;BR /&gt;
data all;&lt;BR /&gt;
  set %names(hist9.Aae,2000,5);&lt;BR /&gt;
  	keep asc;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
So if the code runs correctly, it will build data all with data sets hist9.aae200001 - hist9.200005.&lt;BR /&gt;
&lt;BR /&gt;
The problem is when it processes it is looking for a one digit month, so 1,2,3...instead of 01, 02, 03...so it stops without working.&lt;BR /&gt;
&lt;BR /&gt;
Any thoughts?</description>
      <pubDate>Wed, 09 Aug 2006 14:45:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Macro-question/m-p/1225#M567</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2006-08-09T14:45:03Z</dc:date>
    </item>
    <item>
      <title>Re: Macro question</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Macro-question/m-p/1226#M568</link>
      <description>Use the Z format for leading zeros.&lt;BR /&gt;
&lt;BR /&gt;
&amp;amp;lib&amp;amp;year%sysfunc(putn(&amp;amp;dt, z2.));</description>
      <pubDate>Wed, 09 Aug 2006 15:18:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Macro-question/m-p/1226#M568</guid>
      <dc:creator>CarstenM</dc:creator>
      <dc:date>2006-08-09T15:18:17Z</dc:date>
    </item>
    <item>
      <title>Re: Macro question</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Macro-question/m-p/1227#M569</link>
      <description>&lt;B&gt;Well, still can't get it to work...the Enlhist9 is a library that is automatically assigned with my AutoEx? If that helps?&lt;/B&gt; FYI - I changed dt to i.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
84   %macro names(lib,year,maxnum);&lt;BR /&gt;
85           %do i=1 %to &amp;amp;maxnum;&lt;BR /&gt;
86           &amp;amp;lib&amp;amp;year%sysfunc(putn(&amp;amp;i, z2.));&lt;BR /&gt;
87           %end;&lt;BR /&gt;
88   %mend names;&lt;BR /&gt;
&lt;BR /&gt;
89   data all;&lt;BR /&gt;
90     set %names(Enlhist9.Aae,2001,5);&lt;BR /&gt;
SYMBOLGEN:  Macro variable MAXNUM resolves to 5&lt;BR /&gt;
SYMBOLGEN:  Macro variable LIB resolves to Enlhist9.Aae&lt;BR /&gt;
SYMBOLGEN:  Macro variable YEAR resolves to 2001&lt;BR /&gt;
SYMBOLGEN:  Macro variable I resolves to 1&lt;BR /&gt;
MPRINT(NAMES):   Enlhist9.Aae200101;&lt;BR /&gt;
SYMBOLGEN:  Macro variable LIB resolves to Enlhist9.Aae&lt;BR /&gt;
SYMBOLGEN:  Macro variable YEAR resolves to 2001&lt;BR /&gt;
SYMBOLGEN:  Macro variable I resolves to 2&lt;BR /&gt;
NOTE: DATA statement used (Total process time):&lt;BR /&gt;
      real time           0.21 seconds&lt;BR /&gt;
      cpu time            0.00 seconds&lt;BR /&gt;
&lt;BR /&gt;
ERROR: DATA STEP Component Object failure.  Aborted during the COMPILATION phase.&lt;BR /&gt;
NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;
MPRINT(NAMES):   Enlhist9.Aae200102;&lt;BR /&gt;
SYMBOLGEN:  Macro variable LIB resolves to Enlhist9.Aae&lt;BR /&gt;
SYMBOLGEN:  Macro variable YEAR resolves to 2001&lt;BR /&gt;
SYMBOLGEN:  Macro variable I resolves to 3&lt;BR /&gt;
NOTE: Line generated by the macro function "SYSFUNC".&lt;BR /&gt;
1             Enlhist9.Aae200102&lt;BR /&gt;
              ------------------&lt;BR /&gt;
              557&lt;BR /&gt;
MPRINT(NAMES):   Enlhist9.Aae200103;&lt;BR /&gt;
SYMBOLGEN:  Macro variable LIB resolves to Enlhist9.Aae&lt;BR /&gt;
SYMBOLGEN:  Macro variable YEAR resolves to 2001&lt;BR /&gt;
SYMBOLGEN:  Macro variable I resolves to 4&lt;BR /&gt;
MPRINT(NAMES):   Enlhist9.Aae200104;&lt;BR /&gt;
SYMBOLGEN:  Macro variable LIB resolves to Enlhist9.Aae&lt;BR /&gt;
SYMBOLGEN:  Macro variable YEAR resolves to 2001&lt;BR /&gt;
SYMBOLGEN:  Macro variable I resolves to 5&lt;BR /&gt;
MPRINT(NAMES):   Enlhist9.Aae200105;&lt;BR /&gt;
ERROR 557-185: Variable Enlhist9 is not an object.&lt;BR /&gt;
&lt;BR /&gt;
91   run;</description>
      <pubDate>Wed, 09 Aug 2006 17:53:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Macro-question/m-p/1227#M569</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2006-08-09T17:53:14Z</dc:date>
    </item>
    <item>
      <title>Re: Macro question</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Macro-question/m-p/1228#M570</link>
      <description>Hi!&lt;BR /&gt;
  I believe your problem is the semi-colon inside your   %do loop (shown below on line 86): [pre]&lt;BR /&gt;
86 &amp;amp;lib&amp;amp;year%sysfunc(putn(&amp;amp;i, z2.))&lt;B&gt;;&lt;/B&gt;&lt;BR /&gt;
[/pre] That single semi-colon will be generated for EACH filename that you are building. I think that you do NOT need to have this semi-colon here. The whole purpose of the macro is to generate a string of file names for a SET statement. There is only 1 semi-colon for a set statement. Since the macro program is essentially doing your typing for you, the best way to envision this is to work backward from a correct set statement:&lt;BR /&gt;
[pre]&lt;BR /&gt;
  set work.file1 work.file2 work.file3 work.file4;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
  You do NOT want a semi-colon between each of the file names on the set statement. Your statement DOES have a semi-colon so what you are creating is the equivalent of this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
   set work.file1; work.file2; work.file3; work.file4;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
  So you are getting an error message on the filename for the 2nd iteration of the do loop because the libname piece of the name (up to the first dot) is not a SAS keyword and it's not a macro variable that can be resolved and so the data step stops.&lt;BR /&gt;
&lt;BR /&gt;
  To mimic what you are doing, I tested this:&lt;BR /&gt;
[pre]&lt;BR /&gt;
options mprint symbolgen mlogic source2;&lt;BR /&gt;
** make some data files;&lt;BR /&gt;
data work.FIL200601 work.FIL200602  work.FIL200603&lt;BR /&gt;
     work.FIL200604 work.FIL200605 work.FIL200606 &lt;BR /&gt;
     work.FIL200607 work.FIL200608 work.FIL200609&lt;BR /&gt;
     work.FIL200610 work.FIL200611 work.FIL200612;&lt;BR /&gt;
   a=1;    b=2;    c=3;&lt;BR /&gt;
  run;&lt;BR /&gt;
&lt;BR /&gt;
** define the macro program;&lt;BR /&gt;
** note that there is NO semicolon at the end of;&lt;BR /&gt;
** my statement that has Z. format;&lt;BR /&gt;
%macro names(lib,year,maxnum);&lt;BR /&gt;
%do dt=1 %to &amp;amp;maxnum ; &lt;B&gt;&lt;BR /&gt;
    &amp;amp;lib&amp;amp;year%sysfunc(putn(&amp;amp;dt, z2.))&lt;/B&gt;&lt;BR /&gt;
%end;&lt;BR /&gt;
%mend names;&lt;BR /&gt;
&lt;BR /&gt;
** use macro program;&lt;BR /&gt;
** note semi-colon is at the END of the SET statement; ** and NOT inside the names generated by the macro ;&lt;BR /&gt;
data all;&lt;BR /&gt;
  set %names(Work.FIL, 2006,12);&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
** print final data set;&lt;BR /&gt;
proc print data=all;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
And did not get any errors in the log. I can, however, replicate your error message simply by inserting a semi-colon inside the macro do loop.&lt;BR /&gt;
&lt;BR /&gt;
Macro programming is quirky, but fun. The error messages don't always mean what you think they mean. SAS was not telling you that the libname was not assigned...it was trying to tell you that it found a text string that it didn't know how to deal with and that text string just happened to be your libname.&lt;BR /&gt;
&lt;BR /&gt;
cynthia</description>
      <pubDate>Thu, 10 Aug 2006 02:04:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Macro-question/m-p/1228#M570</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2006-08-10T02:04:35Z</dc:date>
    </item>
  </channel>
</rss>

