<?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 evaluate an numeric expression in Developers</title>
    <link>https://communities.sas.com/t5/Developers/How-to-evaluate-an-numeric-expression/m-p/385053#M5460</link>
    <description>&lt;P&gt;This is very simple to do in a DATA step, there's no reason for a macro at all.&lt;/P&gt;</description>
    <pubDate>Wed, 02 Aug 2017 17:02:20 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2017-08-02T17:02:20Z</dc:date>
    <item>
      <title>How to evaluate an numeric expression</title>
      <link>https://communities.sas.com/t5/Developers/How-to-evaluate-an-numeric-expression/m-p/385033#M5457</link>
      <description>&lt;P&gt;Sorry for kind of a SAS noob question here, but here goes:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a simple Stored Process based on an example from the DI Studio user guide, which converts a temperature. &amp;nbsp;I've simplified it to be a stand-alone Stored Process with Inputs/Outputs defined on the Stored Process itself. &amp;nbsp;I'm then accessing it via the SASBIWS "json" URL that we get for any Stored Process when we have SASBIWS. &amp;nbsp;Anyway - here's the Store Proc code:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%global INTEMP INUNIT OUTTEMP OUTUNIT;

%STPBEGIN;

%macro convertTemp;

%let OUTTEMP = -9999.9;
%let OUTUNIT = "";

%if "&amp;amp;INUNIT" = "F" %then
  %do;
    %let OUTTEMP = (5.0/9.0)*((&amp;amp;INTEMP)-32.0);
    %let OUTUNIT = "C";
  %end;
%else %if "&amp;amp;INUNIT" = "C" %then
  %do;
    %let OUTTEMP = ((9.0/5.0)*(&amp;amp;INTEMP))+32.0;
    %let OUTUNIT = "F";
  %end;

%mend;

%convertTemp;
%put OUTTEMP parameter is &amp;amp;OUTTEMP;
%put OUTUNIT parameter is &amp;amp;OUTUNIT;

%STPEND(debug=y);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;INTEMP is defined as a Numeric (double) type; INUNIT is Text type.&lt;/P&gt;&lt;P&gt;So... pretty straightforward. &amp;nbsp;When I call it from a browser using.&lt;/P&gt;&lt;PRE&gt;https://ourserver/SASBIWS/json/storedProcesses/path/StoredProcessName?INTEMP=100&amp;amp;INUNIT=C&lt;/PRE&gt;&lt;P&gt;... the response is:&lt;/P&gt;&lt;PRE&gt;{"outputParameters":{"OUTTEMP":"((9.0/5.0)*(100.0))+32.0","OUTUNIT":"\"F\""}}&lt;/PRE&gt;&lt;P&gt;So... it handles the string INUNIT parameter: it is "C" going in, and the conditional logic gives the "F" in the response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But my question is &lt;EM&gt;why doesn't it evaluate the numeric expression&lt;/EM&gt;: &lt;FONT face="courier new,courier" color="#000080"&gt;((9.0/5.0)*(100.0))+32.0&lt;/FONT&gt; ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 16:11:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/How-to-evaluate-an-numeric-expression/m-p/385033#M5457</guid>
      <dc:creator>JohnJPS</dc:creator>
      <dc:date>2017-08-02T16:11:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to evaluate an numeric expression</title>
      <link>https://communities.sas.com/t5/Developers/How-to-evaluate-an-numeric-expression/m-p/385037#M5458</link>
      <description>&lt;P&gt;As you have seen, macro language doesn't perform math automatically as part of a %LET statement.&amp;nbsp; There are some places within macro language where it will perform the math, but not as part of %LET.&amp;nbsp; So you have to tell it to perform the math:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token macroname"&gt;%let&lt;/SPAN&gt; OUTTEMP &lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt; &lt;FONT color="#ff0000"&gt;%sysevalf(&lt;/FONT&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;5.0&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;/&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;9.0&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;INTEMP&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;-32.0&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;FONT color="#ff0000"&gt;) &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 16:20:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/How-to-evaluate-an-numeric-expression/m-p/385037#M5458</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-08-02T16:20:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to evaluate an numeric expression</title>
      <link>https://communities.sas.com/t5/Developers/How-to-evaluate-an-numeric-expression/m-p/385053#M5460</link>
      <description>&lt;P&gt;This is very simple to do in a DATA step, there's no reason for a macro at all.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 17:02:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/How-to-evaluate-an-numeric-expression/m-p/385053#M5460</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-08-02T17:02:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to evaluate an numeric expression</title>
      <link>https://communities.sas.com/t5/Developers/How-to-evaluate-an-numeric-expression/m-p/385066#M5461</link>
      <description>&lt;P&gt;Well, same question: I can write "non-macro" code, but I have the same issues processing any of the data:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%global INTEMP INUNIT OUTTEMP OUTUNIT;

%STPBEGIN;

data _null_;

  OUTTEMP = 999;
  OUTUNIT = "";

  if "&amp;amp;INUNIT" = "F" then
    do;
      OUTTEMP = (5.0/9.0)*((&amp;amp;INTEMP.)-32.0);
      OUTUNIT = "C";
    end;
  else if "&amp;amp;INUNIT" = "C" then
    do;
      OUTTEMP = ((9.0/5.0)*(&amp;amp;INTEMP.))+32.0;
      OUTUNIT = "F";
    end;

run;

%put OUTTEMP parameter is &amp;amp;OUTTEMP;
%put OUTUNIT parameter is &amp;amp;OUTUNIT;

%STPEND;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When called from a browser, this returns null values:&lt;/P&gt;&lt;PRE&gt;{"outputParameters":{"OUTTEMP":"","OUTUNIT":""}}&lt;/PRE&gt;&lt;P&gt;Still being quite new to SAS, I can't spot what's missing... I've already tried several variations; some give syntax errors; others behave just like this one: running but providing null results.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2017 18:18:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/How-to-evaluate-an-numeric-expression/m-p/385066#M5461</guid>
      <dc:creator>JohnJPS</dc:creator>
      <dc:date>2017-08-02T18:18:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to evaluate an numeric expression</title>
      <link>https://communities.sas.com/t5/Developers/How-to-evaluate-an-numeric-expression/m-p/385082#M5462</link>
      <description>&lt;P&gt;Kinda half and half: this allows me to remove the macro conditional logic, but I still appear to need the macro "%let" statements.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%global INTEMP INUNIT OUTTEMP OUTUNIT;
%STPBEGIN;
%let OUTTEMP = 999;
%let OUTUNIT = "";
data _null_;
  if "&amp;amp;INUNIT" = "F" then
    do;
      %let OUTTEMP = %sysevalf((5.0/9.0)*((&amp;amp;INTEMP.)-32.0));
      %let OUTUNIT = "C";
    end;
  else if "&amp;amp;INUNIT" = "C" then
    do;
      %let OUTTEMP = %sysevalf(((9.0/5.0)*(&amp;amp;INTEMP.))+32.0);
      %let OUTUNIT = "F";
    end;
run;
%put OUTTEMP parameter is &amp;amp;OUTTEMP;
%put OUTUNIT parameter is &amp;amp;OUTUNIT;
%STPEND;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Aug 2017 19:06:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/How-to-evaluate-an-numeric-expression/m-p/385082#M5462</guid>
      <dc:creator>JohnJPS</dc:creator>
      <dc:date>2017-08-02T19:06:53Z</dc:date>
    </item>
  </channel>
</rss>

