<?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: Running Macro in Do-Loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Running-Macro-in-Do-Loop/m-p/94293#M19854</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You have mixed up macro code and data step code. The best way to do this depends on what the macro COLLATERAL is actually doing.&lt;/P&gt;&lt;P&gt;If it is just generating statements to be included within a single data step then you might be able to do something like:&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do increment=1 to 50 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %collateral;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;In that case the macro should be referencing the datastep varaiable INCREMENT rather than using &amp;amp;INCREMENT to expand the value of the macro variable INCREMENT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If it is generating one or more complete DATA or PROC steps then you could wrap it in another macro so that you can use %DO loop instead.&lt;/P&gt;&lt;P&gt;%macro outer(limit);&lt;/P&gt;&lt;P&gt; %do increment=1 %to &amp;amp;limit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %collateral;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%mend outer;&lt;/P&gt;&lt;P&gt;%outer(50);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 13 Oct 2012 12:14:12 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2012-10-13T12:14:12Z</dc:date>
    <item>
      <title>Running Macro in Do-Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-Macro-in-Do-Loop/m-p/94292#M19853</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to run a macro named 'collateral' within a do-loop, such that everytime the do-loop is ran, it a) increments the variable 'increment' and b) the macro 'collateral' and the steps captured in it are also ran. Below is the code that I have so far. The variable 'increment' feeds into the macro 'collateral'; the macro 'collateral' runs fine on its own, but things go awry once I put it into the do-loop below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Maroulator&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%let increment=0;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do until (increment=50);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;amp;increment=&amp;amp;increment+1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %collateral;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 13 Oct 2012 05:20:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-Macro-in-Do-Loop/m-p/94292#M19853</guid>
      <dc:creator>maroulator</dc:creator>
      <dc:date>2012-10-13T05:20:46Z</dc:date>
    </item>
    <item>
      <title>Re: Running Macro in Do-Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-Macro-in-Do-Loop/m-p/94293#M19854</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You have mixed up macro code and data step code. The best way to do this depends on what the macro COLLATERAL is actually doing.&lt;/P&gt;&lt;P&gt;If it is just generating statements to be included within a single data step then you might be able to do something like:&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;&amp;nbsp; do increment=1 to 50 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %collateral;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;In that case the macro should be referencing the datastep varaiable INCREMENT rather than using &amp;amp;INCREMENT to expand the value of the macro variable INCREMENT.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If it is generating one or more complete DATA or PROC steps then you could wrap it in another macro so that you can use %DO loop instead.&lt;/P&gt;&lt;P&gt;%macro outer(limit);&lt;/P&gt;&lt;P&gt; %do increment=1 %to &amp;amp;limit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %collateral;&lt;/P&gt;&lt;P&gt;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%mend outer;&lt;/P&gt;&lt;P&gt;%outer(50);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 13 Oct 2012 12:14:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-Macro-in-Do-Loop/m-p/94293#M19854</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-10-13T12:14:12Z</dc:date>
    </item>
    <item>
      <title>Re: Running Macro in Do-Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-Macro-in-Do-Loop/m-p/94294#M19855</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tom,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks; this is very helpful. Just two more questions referring to the code that I have thus far. This is an abridged version of my collateral macro; the whole thing contains 5 datasteps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1) At the end of the day, I need the variable INCREMENT in the OUTER macro to stop increasing when the variable NEWASSESSED_FEES in the very last datastep of the COLLATERAL macro reaches 0 (or a value very close to 0).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2) The variable INCREMENT will be taking values anywhere from 0 to 35,000,000; is there a way to have the code not iterate 35 million times? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Christos&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let wvr=150;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro outer(limit);&lt;/P&gt;&lt;P&gt;%do increment=0 %to &amp;amp;limit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %collateral;&lt;/P&gt;&lt;P&gt;%end;&lt;BR /&gt;%mend outer;&lt;/P&gt;&lt;P&gt;%outer(1000);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro collateral();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table all_daily_fees4 as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select aba, sum(daily_cr_net) as newrmp_cr_net&lt;/P&gt;&lt;P&gt;&amp;nbsp; from all_daily_fees3&lt;/P&gt;&lt;P&gt;&amp;nbsp; group by aba;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data rmp_fees;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set all_daily_fees4;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newassessed_fees=newrmp_cr_net-&amp;amp;wvr;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend collateral;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 13 Oct 2012 15:20:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-Macro-in-Do-Loop/m-p/94294#M19855</guid>
      <dc:creator>maroulator</dc:creator>
      <dc:date>2012-10-13T15:20:50Z</dc:date>
    </item>
    <item>
      <title>Re: Running Macro in Do-Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-Macro-in-Do-Loop/m-p/94295#M19856</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif; font-size: 12pt;"&gt;You need to set a macro variable that you can test to stop the loop.&amp;nbsp; Because you are doing it in a nested macro call then make sure the target macro variable exists before the inner macro is called so that the value can persist after the inner macro has terminated. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif; font-size: 12pt;"&gt;The macro %DO statement is not as flexible as the data step DO statement so you will probably want to change to using a %DO %WHILE and manually incrementing the counter.&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif; font-size: 12pt;"&gt;(It is not clear what the increment variable is intended to do? Is it just used as an upper bound on the number of iterations? or is its value involved in the logic of the complete version of COLLATERAL macro?)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, sans-serif; font-size: 12pt;"&gt;Something like below might work.&amp;nbsp; Note that it will set the FINISH variable to 1 (true) when any of the ABA groups reaches a value less than &amp;amp;FUZZ.&amp;nbsp; If you intended it to stop when all are close to zero then you need to change the logic.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let wvr=150;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let fuzz=0.0001;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%macro outer(limit);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let finish=0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let increment=0;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%do %while ( (&lt;SPAN style="background-color: #ffffff;"&gt;&amp;amp;increment &amp;lt; &amp;amp;limit) and not &amp;amp;finish &lt;/SPAN&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %let increment = %eval(&amp;amp;increment + 1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; %collateral;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%end;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%put Increment=&amp;amp;increment Finish=&amp;amp;finish;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%mend outer;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%macro collateral;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;proc sql;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; create table all_daily_fees4 as&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select aba&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; , sum(daily_cr_net) as newrmp_cr_net&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from all_daily_fees3&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by aba&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;quit;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data rmp_fees;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; set all_daily_fees4;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; newassessed_fees=newrmp_cr_net-&amp;amp;wvr;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; if abs(&lt;SPAN style="background-color: #ffffff;"&gt;newassessed_fees&lt;/SPAN&gt;) &amp;lt; &amp;amp;fuzz then call symputx('finish','1');&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%mend collateral;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%outer(1000);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 13 Oct 2012 17:03:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-Macro-in-Do-Loop/m-p/94295#M19856</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-10-13T17:03:51Z</dc:date>
    </item>
    <item>
      <title>Re: Running Macro in Do-Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-Macro-in-Do-Loop/m-p/94296#M19857</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tom, my apologies; I should've sent you my entire code such that the INCREMENT variable was included. Here it is below; all variables partaking in calculations are numeric. The INCREMENT variable increases the value of the numeric variable COLLATERAL2; the goal is to capture the value of INCREMENT (with INCREMENT starting at zero), such that variable NEWASSESSED_FEES goes to zero. My questions (1) and (2) above still stand; would that change the code that you propose above?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro collateral();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; data all_daily_fees;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set all_daily_fees;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; collateral2=collateral+&amp;amp;increment;&lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data all_daily_fees2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set all_daily_fees;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if newbal&amp;lt;0 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if abs(newbal)&amp;gt;collateral2 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newcollod2=collateral2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newuncollod2=abs((collateral2+newbal));&lt;/P&gt;&lt;P&gt;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; else do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newcollod2=abs(newbal);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newuncollod2=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; newcollod2=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; newuncollod2=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data all_daily_fees3;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set all_daily_fees2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if fee_cd='F' then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if newbal&amp;lt;0 then newdaily_cr_net=&amp;amp;ed_uc_rate*(newUnCollOD2)/1291;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else newdaily_cr_net=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; create table all_daily_fees4 as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; select aba, sum(newdaily_cr_net) as newrmp_cr_net&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; from all_daily_fees3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; group by aba;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data rmp_fees;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set all_daily_fees4;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; newassessed_fees=newrmp_cr_net-&amp;amp;wvr;&lt;/P&gt;&lt;P&gt; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro outer(limit);&lt;/P&gt;&lt;P&gt;%do increment=31999000 %to &amp;amp;limit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %collateral;&lt;/P&gt;&lt;P&gt; %end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend outer;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%outer(32000000);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 14 Oct 2012 01:11:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-Macro-in-Do-Loop/m-p/94296#M19857</guid>
      <dc:creator>maroulator</dc:creator>
      <dc:date>2012-10-14T01:11:51Z</dc:date>
    </item>
    <item>
      <title>Re: Running Macro in Do-Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-Macro-in-Do-Loop/m-p/94297#M19858</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;One more thing; what is the purpose of the 'not &amp;amp;finish'&amp;nbsp; in the do-while part of the macro 'outer'? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 14 Oct 2012 03:53:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-Macro-in-Do-Loop/m-p/94297#M19858</guid>
      <dc:creator>maroulator</dc:creator>
      <dc:date>2012-10-14T03:53:56Z</dc:date>
    </item>
    <item>
      <title>Re: Running Macro in Do-Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-Macro-in-Do-Loop/m-p/94298#M19859</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You wanted a method to stop the looping.&amp;nbsp; So the idea I proposed and demonstrated was to use a macro variable that will be set by the inner macro when the stopping criteria has been met.&amp;nbsp; I decided to call that macro variable FINISH and code it as binary 0/1 values (0 is false and 1 is true or "finished").&amp;nbsp; So before beginning the loop I set FINISH to 0 (false) and then within the macro it conditionally sets the value to 1 (true).&amp;nbsp; So then the (NOT &amp;amp;finish) condition in the %DO %WHILE loop will become false so it will stop calling the inner macro.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 14 Oct 2012 17:53:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-Macro-in-Do-Loop/m-p/94298#M19859</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-10-14T17:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: Running Macro in Do-Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-Macro-in-Do-Loop/m-p/94299#M19860</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks! Is there a way of taking the value of INCREMENT after the %do-%while stops and putting it into a table?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Oct 2012 00:38:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-Macro-in-Do-Loop/m-p/94299#M19860</guid>
      <dc:creator>maroulator</dc:creator>
      <dc:date>2012-10-15T00:38:03Z</dc:date>
    </item>
    <item>
      <title>Re: Running Macro in Do-Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-Macro-in-Do-Loop/m-p/94300#M19861</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Many thanks for the help thus far. I have what I am hoping to be my last question.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below is the code that we have been discussing thus far. The difference now is that I have introduced the X macro variable in the OUTER macro and I am re-setting it in the last lines of the COLLATERAL macro depending on the value of DIFFERENCE, such that the variable INCREMENT in the OUTER MACRO gets incremented by X and flows into the COLLATERAL macro. The idea still is to increment the variable INCREMENT such that the DIFFERENCE valiable approaches zero; when DIFFERENCE approaches zero, the outer OUTER should stop calling the COLLATERAL macro. I have not yet tested this approach with the X variable and will not be able to troubleshoot for another day. Could I please have a sanity check on 1) the treatment of variable X, and 2) the 'killing' of the OUTER macro (by way of the binary finish variable) once DIFFERENCE is between -1 and 1. Again below is the code; thanks in advance.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro outer();&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let increment=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let x=0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let finish=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %do %while (&amp;amp;finish);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let increment=%eval(&amp;amp;increment + &amp;amp;x);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%mend outer(); &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%outer();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro collateral();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; data all_daily_fees2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set all_daily_fees;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; collateral2=collateral+&amp;amp;increment;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if newbal&amp;lt;0 then do;&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;&amp;nbsp;&amp;nbsp; if abs(newbal)&amp;gt;collateral2 then do;&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;&amp;nbsp;&amp;nbsp; newcollod2=collateral2;&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;&amp;nbsp;&amp;nbsp; newuncollod2=abs((collateral2+newbal));&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;&amp;nbsp;&amp;nbsp; end;&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;&amp;nbsp;&amp;nbsp; else do;&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;&amp;nbsp;&amp;nbsp; newcollod2=abs(newbal);&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;&amp;nbsp;&amp;nbsp; newcollod2=0;&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;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else do;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; newcollod2=0;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; newuncollod2=0;&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; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &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; if fee_cd='F' then do;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if bal&amp;lt;0 then daily_cr_net=&amp;amp;ed_uc_rate*(UncollOD/1291);&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else daily_cr_net=0;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if newbal&amp;lt;0 then newdaily_cr_net=&amp;amp;ed_uc_rate*(newUncollOD2/1291);&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else newdaily_cr_net=0;&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;&amp;nbsp; end;&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; create table all_daily_fees4 as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select aba, sum(daily_cr_net) as rmp_cr_net, sum(newdaily_cr_net) as&amp;nbsp;&amp;nbsp; newrmp_cr_net&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from all_daily_fees3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by aba;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data rmp_fees;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set all_daily_fees4;&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; assessed_fees=max(0, rmp_cr_net-&amp;amp;wvr);&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; newassessed_fees=max(0,newrmp_cr_net-&amp;amp;wvr);&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; difference=newassessed_fees-assessed_fees;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if difference between 10000000 and 100 then %let x=1000000; /*If difference is between 10000000 and 100, reset x to 1000000*/&lt;/P&gt;&lt;P&gt;&amp;nbsp; if difference between 100 and 10 then %let x=1000;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if difference between 1 and 10 then %let x=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp; if difference between -1 and 1 then call symputx('finish',0); /*If difference is between -1 and 1, kill the %outer macro*/&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend collateral();&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Oct 2012 03:10:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-Macro-in-Do-Loop/m-p/94300#M19861</guid>
      <dc:creator>maroulator</dc:creator>
      <dc:date>2012-10-17T03:10:26Z</dc:date>
    </item>
    <item>
      <title>Re: Running Macro in Do-Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Running-Macro-in-Do-Loop/m-p/94301#M19862</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Tom,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you get a chance, could you please take a look at the latest comment in the discussion? I accidentally replied to myself.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Christos&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Oct 2012 03:20:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Running-Macro-in-Do-Loop/m-p/94301#M19862</guid>
      <dc:creator>maroulator</dc:creator>
      <dc:date>2012-10-17T03:20:31Z</dc:date>
    </item>
  </channel>
</rss>

