<?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: Arithmetic calculation in macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-in-macro/m-p/435926#M108329</link>
    <description>data temp; set temp;&lt;BR /&gt;right? so that temp is used repeatedly?</description>
    <pubDate>Sat, 10 Feb 2018 05:20:12 GMT</pubDate>
    <dc:creator>Cruise</dc:creator>
    <dc:date>2018-02-10T05:20:12Z</dc:date>
    <item>
      <title>Arithmetic calculation in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-in-macro/m-p/435921#M108324</link>
      <description>&lt;P&gt;I'd like to compute &amp;amp;rate across the range of variable 'scale' takes. Data 'want' then would have rate01 thru rate2 across all scales. But my code below produces only one column for a single rate.&lt;/P&gt;&lt;P&gt;Any idea why my code fails to create &amp;amp;rate for whole range?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;amp;rate=(agerisk*&amp;amp;scale)/tot_pop;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="macro want.png" style="width: 249px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/18442i7C572F049A8D4675/image-dimensions/249x251?v=v2" width="249" height="251" role="button" title="macro want.png" alt="macro want.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
input tot_pop agerisk;
datalines;
15286	0.055
57522	0.217
28017	0.066
21669	0.064
17853	0.071
17325	0.080
19893	0.081
22637	0.072
22788	0.062
21019	0.048
17881	0.038
11968	0.034
8676	0.031
21670	0.060
;

%symdel;
%macro models(rate,scale);
data want; set temp;
&amp;amp;rate=(agerisk*&amp;amp;scale)/tot_pop;
run;
%mend models;
%models(rate01,0.1);
%models(rate02,0.2);
%models(rate03,0.3);
%models(rate04,0.4);
%models(rate05,0.5);
%models(rate06,0.6);
%models(rate07,0.7);
%models(rate08,0.8);
%models(rate09,0.9);
%models(rate1,1);
%models(rate11,1.1);
%models(rate12,1.2);
%models(rate13,1.3);
%models(rate14,1.4);
%models(rate15,1.5);
%models(rate16,1.6);
%models(rate17,1.7);
%models(rate18,1.8);
%models(rate19,1.9);
%models(rate2,2);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 10 Feb 2018 04:45:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-in-macro/m-p/435921#M108324</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-02-10T04:45:04Z</dc:date>
    </item>
    <item>
      <title>Re: Arithmetic calculation in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-in-macro/m-p/435925#M108328</link>
      <description>&lt;P&gt;Because you always start from the TEMP data set so no previous changes are maintained.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically you overwrite your results with each iteration, so you need to reuse the data set in this case if you want to include the previous results.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Feb 2018 05:14:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-in-macro/m-p/435925#M108328</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-10T05:14:24Z</dc:date>
    </item>
    <item>
      <title>Re: Arithmetic calculation in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-in-macro/m-p/435926#M108329</link>
      <description>data temp; set temp;&lt;BR /&gt;right? so that temp is used repeatedly?</description>
      <pubDate>Sat, 10 Feb 2018 05:20:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-in-macro/m-p/435926#M108329</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-02-10T05:20:12Z</dc:date>
    </item>
    <item>
      <title>Re: Arithmetic calculation in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-in-macro/m-p/435928#M108331</link>
      <description>&lt;P&gt;Try it&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/132289"&gt;@Cruise&lt;/a&gt; wrote:&lt;BR /&gt;data temp; set temp;&lt;BR /&gt;right? so that temp is used repeatedly?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Feb 2018 05:27:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-in-macro/m-p/435928#M108331</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-02-10T05:27:36Z</dc:date>
    </item>
    <item>
      <title>Re: Arithmetic calculation in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-in-macro/m-p/435930#M108333</link>
      <description>worked out! Thanks Reeza.</description>
      <pubDate>Sat, 10 Feb 2018 05:32:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-in-macro/m-p/435930#M108333</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-02-10T05:32:43Z</dc:date>
    </item>
    <item>
      <title>Re: Arithmetic calculation in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-in-macro/m-p/435933#M108334</link>
      <description>&lt;P&gt;Since your rates are just .1,.2.3,... you could easily do this without macro code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set temp;
  array rate rate01-rate20;
  do i=1 to dim(rate);
    rate(i) = (agerisk*(i/10))/tot_pop;
  end;
  drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 10 Feb 2018 05:56:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-in-macro/m-p/435933#M108334</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-02-10T05:56:24Z</dc:date>
    </item>
    <item>
      <title>Re: Arithmetic calculation in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-in-macro/m-p/435978#M108352</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&lt;/P&gt;&lt;P&gt;What if rate01-rate20 wasn't known? I eventually would use more granular integers where I have no idea of n points in the range?&lt;/P&gt;</description>
      <pubDate>Sat, 10 Feb 2018 19:30:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-in-macro/m-p/435978#M108352</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-02-10T19:30:59Z</dc:date>
    </item>
    <item>
      <title>Re: Arithmetic calculation in macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-in-macro/m-p/435981#M108355</link>
      <description>&lt;P&gt;Use a separate array for the list of "scale" values.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if I had 5 "scale" values I could use a program like this to calculate 5 new "rate" variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set temp;
  array rate (5) ;
  array scale (5) _temporary_ (.1 .25 .5 1 1.5) ;
  do i=1 to dim(rate);
    rate(i) = (agerisk*scale(i))/tot_pop;
  end;
  drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could make it dynamic by putting the list of values into a macro variable and then using COUNTW() to find out how many there were.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let scales=.1 .25 .5 1 1.5;
%let n=%sysfunc(countw(&amp;amp;scales,%str( )));
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So then use the macro variables to define the arrays.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  array rate (&amp;amp;n) ;
  array scale (&amp;amp;n) _temporary_ (&amp;amp;scales) ;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 10 Feb 2018 19:42:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Arithmetic-calculation-in-macro/m-p/435981#M108355</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-02-10T19:42:24Z</dc:date>
    </item>
  </channel>
</rss>

