<?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 to translate a list of words in a formula in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-translate-a-list-of-words-in-a-formula/m-p/949220#M371344</link>
    <description>&lt;P&gt;Thanks a lot it works !&lt;/P&gt;</description>
    <pubDate>Mon, 28 Oct 2024 11:45:21 GMT</pubDate>
    <dc:creator>J111</dc:creator>
    <dc:date>2024-10-28T11:45:21Z</dc:date>
    <item>
      <title>How to translate a list of words in a formula</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-translate-a-list-of-words-in-a-formula/m-p/949192#M371331</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please find below data &lt;STRONG&gt;have&lt;/STRONG&gt; and data &lt;STRONG&gt;want&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;We have a list of formula using&amp;nbsp;&lt;STRONG&gt;variables&lt;/STRONG&gt; such as x, y z.&lt;/P&gt;
&lt;P&gt;Note that some rows of the &lt;STRONG&gt;formula&lt;/STRONG&gt;&amp;nbsp;file use macros such as movave.&lt;/P&gt;
&lt;P&gt;We want all variables in the formula to have brackets, for example [x] instead of x.&lt;/P&gt;
&lt;P&gt;There are thousands of variables and thousands of rows with formula.&lt;/P&gt;
&lt;P&gt;In addition, we can supply a distinct list of all &lt;STRONG&gt;variables.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;In other words, all variables in the formula should be translated to variables with brackets&lt;/P&gt;
&lt;P&gt;for example translate x to [x], perhaps like this:-&lt;/P&gt;
&lt;P&gt;formula = tranwrd(formula ,'x' ,'[x]' ) ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;BR /&gt;data &lt;STRONG&gt;have&lt;/STRONG&gt; ;&lt;BR /&gt;input formula $200 ;&lt;BR /&gt;cards ;&lt;BR /&gt;x/y + z&lt;BR /&gt;w-x ** z&lt;BR /&gt;movave(x)&lt;BR /&gt;;&lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data &lt;STRONG&gt;want&lt;/STRONG&gt; ;&lt;BR /&gt;input formula $200 ;&lt;BR /&gt;cards ;&lt;BR /&gt;[x]/[y] + [z]&lt;BR /&gt;[w]-[x] ** [z]&lt;BR /&gt;%movave([x])&lt;BR /&gt;;&lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data &lt;STRONG&gt;variables&amp;nbsp;&lt;/STRONG&gt; ;&lt;BR /&gt;input without $50 with $50 ;&lt;BR /&gt;x [x]&lt;BR /&gt;y [y]&lt;BR /&gt;z [z]&lt;BR /&gt;;&lt;BR /&gt;run ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2024 09:43:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-translate-a-list-of-words-in-a-formula/m-p/949192#M371331</guid>
      <dc:creator>J111</dc:creator>
      <dc:date>2024-10-28T09:43:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to translate a list of words in a formula</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-translate-a-list-of-words-in-a-formula/m-p/949212#M371340</link>
      <description>&lt;P&gt;You could try something like below. It should work as long as you don't have variable names in your formulas with the same name like functions or formats etc.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover dsd dlm=',';
  input formula_have :$200. formula_want :$200.;
  cards;
x/y + z,  [x]/[y] + [z]
w-x ** z, [w]-[x] ** [z]
movave(x),%movave([x])
;
run;

data variables;
  input without :$50. with :$50.;
  datalines;
x [x]
y [y]
z [z]
;
run;

filename codegen temp;
data _null_;
  file codegen;
  set variables;
  cmd= cats('formula_derived=prxchange("s/\b',without,'\b/',with,'/oi",-1,strip(formula_derived));');
  put cmd;
run;

data want;
  set have;
  formula_derived=formula_have;
  %include codegen / source2;
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 28 Oct 2024 11:20:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-translate-a-list-of-words-in-a-formula/m-p/949212#M371340</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-10-28T11:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to translate a list of words in a formula</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-translate-a-list-of-words-in-a-formula/m-p/949220#M371344</link>
      <description>&lt;P&gt;Thanks a lot it works !&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2024 11:45:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-translate-a-list-of-words-in-a-formula/m-p/949220#M371344</guid>
      <dc:creator>J111</dc:creator>
      <dc:date>2024-10-28T11:45:21Z</dc:date>
    </item>
  </channel>
</rss>

