<?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: Nested Macro question in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Nested-Macro-question/m-p/197318#M49304</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It is the execution of the macros that is nested, not the definition. So move the %macro year... %mend year lines to the top of the program.&lt;/P&gt;&lt;P&gt;Note that your %YEAR() macro is overwriting its input so you cannot call it twice within the other macro without it failing.&lt;/P&gt;&lt;P&gt;Turn the MPRINT option to see what code the macros are really generating.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 07 Jul 2015 17:26:57 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2015-07-07T17:26:57Z</dc:date>
    <item>
      <title>Nested Macro question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Nested-Macro-question/m-p/197315#M49301</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Good afternoon, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am having an issue with a nested macro. My code is listed below. The first time (1998) the %year macro is running, there is no problem. ODS is creating the datastats_1998 data set with whatever I need. The second time it runs (1999) I get the following message in the log, which makes me think that I have forgotten something in ODS. I tried to use "ods output close" at the end of the macro, but it did not fix the problem. Does anybody know what am I doing wrong? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;WARNING: Output 'ChiSq' was not created.&amp;nbsp; Make sure that the output object name, label, or path&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; is spelled correctly.&amp;nbsp; Also, verify that the appropriate procedure options are used to&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; produce the requested output object.&amp;nbsp; For example, verify that the NOPRINT option is&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; not used.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro center(center);&lt;/P&gt;&lt;P&gt;data frequency;&lt;/P&gt;&lt;P&gt;set irnd;&lt;/P&gt;&lt;P&gt;where center=&amp;amp;center;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%Macro year(year);&lt;/P&gt;&lt;P&gt;data frequency;&lt;/P&gt;&lt;P&gt;length check $20;&lt;/P&gt;&lt;P&gt;set frequency;&lt;/P&gt;&lt;P&gt;if year=&amp;amp;year then check="&amp;amp;year"; &lt;/P&gt;&lt;P&gt;else if year=&amp;amp;year+1 then check="Next Year";&lt;/P&gt;&lt;P&gt;else delete;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ods output ChiSq=datastats_&amp;amp;year;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc freq data=frequency;&lt;/P&gt;&lt;P&gt;tables OCGRDCLN*check / chisq;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print data=datastats_&amp;amp;year;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend year;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%year(1998)&lt;/P&gt;&lt;P&gt;%year(1999)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend center;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%center(3)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Jul 2015 16:55:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Nested-Macro-question/m-p/197315#M49301</guid>
      <dc:creator>Greek</dc:creator>
      <dc:date>2015-07-07T16:55:04Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Macro question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Nested-Macro-question/m-p/197316#M49302</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It is generally considered a bad idea to define a macro within another macro as debugging gets much more complex.&lt;/P&gt;&lt;P&gt;It would be better to define the Year macro separately and pass any additional information needed as parameters, or possibly one macro passing the Center and Year parameters.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You might try putting the ods output ChiSq=datastats_&amp;amp;year; within the proc freq code.&lt;/P&gt;&lt;P&gt;proc freq data=frequency;&lt;/P&gt;&lt;P&gt;tables OCGRDCLN*check / chisq;&lt;/P&gt;&lt;P&gt;ods output ChiSq=datastats_&amp;amp;year;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So the output goes along with the actual version of the procedure run.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Jul 2015 17:14:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Nested-Macro-question/m-p/197316#M49302</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-07-07T17:14:33Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Macro question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Nested-Macro-question/m-p/197317#M49303</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I agree with ballardw's suggestion ... bad form to define one macro inside the definition of another macro.&amp;nbsp; But as to your problem, it has a different source.&amp;nbsp; You are reusing the FREQUENCY data set several times.&amp;nbsp; After running %year(1998), there are only two years left in the FREQUENCY data set (1998 and 1999).&amp;nbsp; When you next run %year(1999), you are deleting the 1998 observations, and are left with only 1999 observations.&amp;nbsp; You don't end up with any year=2000 observations, because those were deleted when running %year(1998).&amp;nbsp; With only one year of data, it's not possible to compute chi squares.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Jul 2015 17:23:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Nested-Macro-question/m-p/197317#M49303</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-07-07T17:23:56Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Macro question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Nested-Macro-question/m-p/197318#M49304</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It is the execution of the macros that is nested, not the definition. So move the %macro year... %mend year lines to the top of the program.&lt;/P&gt;&lt;P&gt;Note that your %YEAR() macro is overwriting its input so you cannot call it twice within the other macro without it failing.&lt;/P&gt;&lt;P&gt;Turn the MPRINT option to see what code the macros are really generating.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Jul 2015 17:26:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Nested-Macro-question/m-p/197318#M49304</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-07-07T17:26:57Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Macro question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Nested-Macro-question/m-p/197319#M49305</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You could make the YEAR() macro just run with a WHERE clause instead of making a new dataset,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro year(year);&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;ods output ChiSq=datastats_&amp;amp;year;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; proc freq data=frequency;&lt;/P&gt;&lt;P&gt;&amp;nbsp; where year in (&amp;amp;year,%eval(&amp;amp;year+1));&lt;/P&gt;&lt;P&gt;&amp;nbsp; tables OCGRDCLN*&amp;amp;year / chisq;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print data=datastats_&amp;amp;year;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;%mend year;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Jul 2015 17:45:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Nested-Macro-question/m-p/197319#M49305</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-07-07T17:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Macro question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Nested-Macro-question/m-p/197320#M49306</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank so much everyone! &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Jul 2015 18:56:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Nested-Macro-question/m-p/197320#M49306</guid>
      <dc:creator>Greek</dc:creator>
      <dc:date>2015-07-07T18:56:41Z</dc:date>
    </item>
    <item>
      <title>Re: Nested Macro question</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Nested-Macro-question/m-p/197321#M49307</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;several respondents said "it is bad form to define one macro completely within another"&lt;/P&gt;&lt;P&gt;and I agree.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;While this may be a common practice in other languages, for scoping reasons etc.,&lt;/P&gt;&lt;P&gt;in the SAS macro language&lt;/P&gt;&lt;P&gt;every time the outer macro is called the inner macro is recompiled, again.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For trivial demonstration macros, we can probably not see the difference in time used.&lt;/P&gt;&lt;P&gt;However, for large macros written by programmers with a 'works-there-let's-do-it-here' attitude&lt;/P&gt;&lt;P&gt;this can be a show-stopper when it comes to optimizing&lt;/P&gt;&lt;P&gt;because the macro processing does not have timing notes like SAS steps do.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I recommend keeping macros small, in separate files,&lt;/P&gt;&lt;P&gt;so both unit and integration tests can be done separately.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 Jul 2015 21:09:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Nested-Macro-question/m-p/197321#M49307</guid>
      <dc:creator>Ron_MacroMaven</dc:creator>
      <dc:date>2015-07-07T21:09:38Z</dc:date>
    </item>
  </channel>
</rss>

