<?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: How do I use a macro to do repeptitive calculations? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-a-macro-to-do-repeptitive-calculations/m-p/821046#M324133</link>
    <description>&lt;P&gt;Large economy sized: Same operation , multiple variables on a single observation usually points to an Array or multiple array, based solution.&lt;/P&gt;</description>
    <pubDate>Wed, 29 Jun 2022 23:39:44 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2022-06-29T23:39:44Z</dc:date>
    <item>
      <title>How do I use a macro to do repeptitive calculations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-a-macro-to-do-repeptitive-calculations/m-p/821033#M324124</link>
      <description>&lt;P&gt;I'm trying to write a program do so some simple calculations (projections across years). I could do the calculations manually, but that's time consuming and clunky:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data proj; 
	set combined;
	deaths2015=(pop1yr*mort_rate)/100000; 
	atrisk2015=pop1yr-deaths2015; 
	expected2015=(atrisk2015*rate_CR)/100000;

	deaths2016=((atrisk2015-expected2015)*mort_rate)/100000;
	atrisk2016=(atrisk2015-expected2015-deaths2016); 
	expected2016=(atrisk2016*rate_CR)/100000; 

	deaths2017=((atrisk2016-expected2016)*mort_rate)/100000; 
	atrisk2017=(atrisk2016-expected2016-deaths2016);
	expected2017=(atrisk2017*rate_CR)/1000000;
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;They need to go out until 2038. For 2016 and onward the calculations reference the previously calculated values. I imagine I could write a macro variables atrisk&amp;amp;i and expected&amp;amp;i to be able to increase the these by year, but I can't quite wrap my head about how to structure it so that it references the previously calculated value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!!&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2022 21:38:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-a-macro-to-do-repeptitive-calculations/m-p/821033#M324124</guid>
      <dc:creator>epialy</dc:creator>
      <dc:date>2022-06-29T21:38:50Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use a macro to do repeptitive calculations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-a-macro-to-do-repeptitive-calculations/m-p/821035#M324126</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data proj; 
	set combined;
	deaths2015=(pop1yr*mort_rate)/100000; 
	atrisk2015=pop1yr-deaths2015; 
	expected2015=(atrisk2015*rate_CR)/100000;

       array _deaths(2015:2038) deaths2015-deaths2038;
       array _atrisk(2015:2038) atrisk2015-atrisk2038;
       array _expected(2015:2038) expected2015-expected2038;

     do i=2016 to 2038;
    	_deaths(i)=((_atrisk(i-1)-_expected(i-1)*mort_rate)/100000;
	_atrisk(i)=(_atrisk(i-1)-_expected(i-1)-_deaths(i)); 
	_expected(i)=(_atrisk(i)*rate_CR)/100000; 
    end;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Arrays, not macros.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's a tutorial on using Arrays in SAS&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-arrays/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-arrays/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2022 21:49:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-a-macro-to-do-repeptitive-calculations/m-p/821035#M324126</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-06-29T21:49:32Z</dc:date>
    </item>
    <item>
      <title>Re: How do I use a macro to do repeptitive calculations?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-a-macro-to-do-repeptitive-calculations/m-p/821046#M324133</link>
      <description>&lt;P&gt;Large economy sized: Same operation , multiple variables on a single observation usually points to an Array or multiple array, based solution.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jun 2022 23:39:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-use-a-macro-to-do-repeptitive-calculations/m-p/821046#M324133</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-06-29T23:39:44Z</dc:date>
    </item>
  </channel>
</rss>

