<?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: Applying multiple formulas located in a column to calculate rates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Applying-multiple-formulas-located-in-a-column-to-calculate/m-p/873295#M345037</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp1;
format formula $200.;
input formula $ num denom num_admin num_ehr elig_pop;
datalines;
num/denom 17 250 . . .
num_admin+num_ehr/elig_pop . . 5 10 350
num+num_admin+num_ehr/elig_pop 14 . 4 18 400
;
run;
data want;
 set temp1;
 array x{*} num--elig_pop;
 do i=1 to dim(x);
   formula=prxchange(cats('s/\b',vname(x{i}),'\b/',x{i},'/i'),-1,formula);
 end;
 want=input(resolve(cats('%sysevalf(',formula,')')),best32.);
 drop i;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 02 May 2023 03:31:16 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2023-05-02T03:31:16Z</dc:date>
    <item>
      <title>Applying multiple formulas located in a column to calculate rates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applying-multiple-formulas-located-in-a-column-to-calculate/m-p/873253#M345024</link>
      <description>&lt;P&gt;I have a CSV file that has a character variable of multiple formulas which reference the other variables in the dataset. I have tried to use the call execute function to apply that and it worked for only like 4 variables but I have 50 variables and 20 different formulas and feel like there is an easier way to resolve these formulas. I have 3500 obs in the dataset so using the call execute is taking forever.&lt;/P&gt;&lt;P&gt;My code below is just super simple using call execute. Could I use an array? Any help would be awesome!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data temp1;&lt;BR /&gt;format formula $200.;&lt;BR /&gt;input formula $ num denom num_admin num_ehr elig_pop;&lt;BR /&gt;datalines;&lt;BR /&gt;num/denom 17 250 . . .&lt;BR /&gt;num_admin+num_ehr/elig_pop . . 5 10 350&lt;BR /&gt;num+num_admin+num_ehr/elig_pop 14 . 4 18 400&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data temp2;&lt;BR /&gt;set temp1;&lt;BR /&gt;if _n_ eq 1 then call execute('data result;');&lt;BR /&gt;call execute(cats('num=',num,';'));&lt;BR /&gt;call execute(cats('denom=',denom,';'));&lt;BR /&gt;call execute(cats('num_admin=',num_admin,';'));&lt;BR /&gt;call execute(cats('num_ehr=',num_ehr,';'));&lt;BR /&gt;call execute(cats('elig_pop=',elig_pop,';'));&lt;BR /&gt;call execute(cats('rate=',formula,';'));&lt;BR /&gt;call execute('output;');&lt;BR /&gt;if last then call execute('run;');&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2023 19:30:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applying-multiple-formulas-located-in-a-column-to-calculate/m-p/873253#M345024</guid>
      <dc:creator>linaibrou</dc:creator>
      <dc:date>2023-05-01T19:30:19Z</dc:date>
    </item>
    <item>
      <title>Re: Applying multiple formulas located in a column to calculate rates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applying-multiple-formulas-located-in-a-column-to-calculate/m-p/873269#M345025</link>
      <description>&lt;P&gt;Not sure how the 3500 obs come into play but based on what you posted this should work. A bunch of lines in there seemed unnecessary.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp1;
format formula $200.;
input formula $ num denom num_admin num_ehr elig_pop;
datalines;
num/denom 17 250 . . .
num_admin+num_ehr/elig_pop . . 5 10 350
num+num_admin+num_ehr/elig_pop 14 . 4 18 400
;
run;

data temp2;
set temp1 end=last;
if _n_ eq 1 then call execute('data result; set temp1;');
call execute(cat('if _n_ =', _n_, ' then rate=',formula,';'));
if last then call execute('run;');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 May 2023 19:57:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applying-multiple-formulas-located-in-a-column-to-calculate/m-p/873269#M345025</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-05-01T19:57:47Z</dc:date>
    </item>
    <item>
      <title>Re: Applying multiple formulas located in a column to calculate rates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applying-multiple-formulas-located-in-a-column-to-calculate/m-p/873274#M345026</link>
      <description>&lt;P&gt;Thank you! I think I was overthinking it. This worked. Appreciate it!&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2023 20:49:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applying-multiple-formulas-located-in-a-column-to-calculate/m-p/873274#M345026</guid>
      <dc:creator>linaibrou</dc:creator>
      <dc:date>2023-05-01T20:49:14Z</dc:date>
    </item>
    <item>
      <title>Re: Applying multiple formulas located in a column to calculate rates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applying-multiple-formulas-located-in-a-column-to-calculate/m-p/873275#M345027</link>
      <description>&lt;P&gt;You likely have an issue with how well that text represents calculations.&lt;/P&gt;
&lt;P&gt;For example you show this:&lt;/P&gt;
&lt;PRE&gt;num_admin+num_ehr/elig_pop . . 5 10 350&lt;/PRE&gt;
&lt;P&gt;A direct translation to SAX code is going to give you the result of num_ehr/elig_pop plus num_admin. But from the third line I really wonder if the interpretation isn't supposed to be&lt;/P&gt;
&lt;PRE&gt;(num_admin+num_ehr)/elig_pop . . 5 10 350&lt;/PRE&gt;
&lt;P&gt;Where num_admin is added to num_erh and that total is then divided by elig_pop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which is correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Arrays really mainly come into power when you do the exact same operation (or at least repeated) for different variables. You haven't shown any example that demonstrates that. You would likely have to show examples of many more calculations. If you formulae are similar enough then the pattern should jump out and let us see if some array might be possible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since all of these:&lt;/P&gt;
&lt;PRE&gt;call execute(cats('num=',num,';'));
call execute(cats('denom=',denom,';'));
call execute(cats('num_admin=',num_admin,';'));
call execute(cats('num_ehr=',num_ehr,';'));
call execute(cats('elig_pop=',elig_pop,';'));&lt;/PRE&gt;
&lt;P&gt;create code that looks like&lt;/P&gt;
&lt;PRE&gt;varname=varname; &lt;/PRE&gt;
&lt;P&gt;They are pretty much not needed unless you just want to write/generate ugly redundant code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2023 20:54:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applying-multiple-formulas-located-in-a-column-to-calculate/m-p/873275#M345027</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-05-01T20:54:42Z</dc:date>
    </item>
    <item>
      <title>Re: Applying multiple formulas located in a column to calculate rates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Applying-multiple-formulas-located-in-a-column-to-calculate/m-p/873295#M345037</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp1;
format formula $200.;
input formula $ num denom num_admin num_ehr elig_pop;
datalines;
num/denom 17 250 . . .
num_admin+num_ehr/elig_pop . . 5 10 350
num+num_admin+num_ehr/elig_pop 14 . 4 18 400
;
run;
data want;
 set temp1;
 array x{*} num--elig_pop;
 do i=1 to dim(x);
   formula=prxchange(cats('s/\b',vname(x{i}),'\b/',x{i},'/i'),-1,formula);
 end;
 want=input(resolve(cats('%sysevalf(',formula,')')),best32.);
 drop i;
 run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 May 2023 03:31:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Applying-multiple-formulas-located-in-a-column-to-calculate/m-p/873295#M345037</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-05-02T03:31:16Z</dc:date>
    </item>
  </channel>
</rss>

