<?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 MACRO within a MACRO problems. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/MACRO-within-a-MACRO-problems/m-p/41292#M8463</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ha...&amp;nbsp; Confused is exactly what I was!&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; Moving the calculate macro outside of loop was exactly what I needed to do!&amp;nbsp; Thanks Tom!&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 30 Jan 2012 17:37:47 GMT</pubDate>
    <dc:creator>Milo08</dc:creator>
    <dc:date>2012-01-30T17:37:47Z</dc:date>
    <item>
      <title>MACRO within a MACRO problems.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-within-a-MACRO-problems/m-p/41289#M8460</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am a relative novice at SAS coding.&amp;nbsp; I am attempting to write a MACRO that will continue to call another MACRO until all calculations over a certain threshold have been removed.&amp;nbsp; After each record gets removed over the threshold I need to re-calculate.&amp;nbsp; The basic structure looks something similar to this.&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%MACRO Loop (var1, var2);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let stop = 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %Do %until (&amp;amp;stop = 0);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%MACRO Calculate (var3, var4, var5, var6, var7, var8);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Make calculations&amp;gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%MEND Calculate;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT cat('%MH_DIF (', var3, ', ', trim(var4), ', ', trim(var5), ', ', var6, ', ', &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; trim(var7), ', ', trim(var8), ' ', ');') into :List separated by ' '&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM AllIData&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; WHERE X = &amp;amp;var1 and Y = "&amp;amp;var2";&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%put &amp;amp;list;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc sort data = &amp;amp;var1_&amp;amp;var2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by descending Calculation;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PROC SQL;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; SELECT calculation, item into :maxvalue, :max&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM &amp;amp;var1_&amp;amp;var2. (OBS=1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %if &amp;amp;maxvalue &amp;gt; 1.5 %then &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data rejects1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set &amp;amp;var1_&amp;amp;var2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where var5 = &amp;amp;max;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Proc append base = rejects new = rejects1 force;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data AllIData;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set AllIData;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where var5 ne &amp;amp;max;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %else %let stop = 0; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%Mend Loop;&lt;/P&gt;&lt;P&gt;%Loop (var1, var2);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The big problems I am noticing are that when I mend my macros there are no lines underneath the MEND statement.&amp;nbsp; Furthermore, when I look at the code underneath the MEND Calculate statement I am seeing color in the code, which should not be there for a MACRO.&amp;nbsp; Finally, after I run the code, I notice in the code editor: * PROC SQL RUNNING after the name of the program.&amp;nbsp; When I separate the two MACROs and run them independently, they run fine.&amp;nbsp; And help would be greatly appreciated!!!&amp;nbsp; Thanks in advance!&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jan 2012 17:02:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-within-a-MACRO-problems/m-p/41289#M8460</guid>
      <dc:creator>Milo08</dc:creator>
      <dc:date>2012-01-30T17:02:43Z</dc:date>
    </item>
    <item>
      <title>MACRO within a MACRO problems.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-within-a-MACRO-problems/m-p/41290#M8461</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure what your actual issue is, but your program structure looks confused. You should move the definition of the macro CALCULATE outside of the definition of the macro LOOP.&amp;nbsp; You should not need to redefine the macro CALCULATE for every iteration inside of LOOP.&amp;nbsp; You just need to call it with different parameter values or input data.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jan 2012 17:15:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-within-a-MACRO-problems/m-p/41290#M8461</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-01-30T17:15:00Z</dc:date>
    </item>
    <item>
      <title>Re: MACRO within a MACRO problems.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-within-a-MACRO-problems/m-p/41291#M8462</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The line that looks like it might cause trouble is &lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code"&gt;%put &amp;amp;list;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You appear to have built the macro variable LIST as one or more calls to the macro MH_DIFF.&amp;nbsp;&amp;nbsp; If that macro expects to generate SAS statements the first one will be "eaten" by the %PUT statement. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you just want to see the value of the macro variable LIST then use &lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code"&gt;%put %superq(list);&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to actually run the macro calls generated into the macro variable then use&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_text_macro jive_macro_code"&gt;&amp;amp;list &lt;BR /&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jan 2012 17:37:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-within-a-MACRO-problems/m-p/41291#M8462</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-01-30T17:37:40Z</dc:date>
    </item>
    <item>
      <title>MACRO within a MACRO problems.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-within-a-MACRO-problems/m-p/41292#M8463</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Ha...&amp;nbsp; Confused is exactly what I was!&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; Moving the calculate macro outside of loop was exactly what I needed to do!&amp;nbsp; Thanks Tom!&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jan 2012 17:37:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-within-a-MACRO-problems/m-p/41292#M8463</guid>
      <dc:creator>Milo08</dc:creator>
      <dc:date>2012-01-30T17:37:47Z</dc:date>
    </item>
    <item>
      <title>MACRO within a MACRO problems.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/MACRO-within-a-MACRO-problems/m-p/41293#M8464</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks again Tom!&amp;nbsp; I removed the %PUT statement and the macro calls worked as they should have! &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 30 Jan 2012 17:45:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/MACRO-within-a-MACRO-problems/m-p/41293#M8464</guid>
      <dc:creator>Milo08</dc:creator>
      <dc:date>2012-01-30T17:45:23Z</dc:date>
    </item>
  </channel>
</rss>

