<?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 validate arithmetic/mathematical expressions in SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-validate-arithmetic-mathematical-expressions-in-SAS/m-p/685185#M207778</link>
    <description>&lt;P&gt;This could give you a clue .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data test;
length expression $15;
input expression $;
result=resolve(cats('%sysevalf(',expression,')'));
datalines;                      
(10+5)/(10-7)
1+2
2-3/4
(6-10)*6
c-10
10+-5
10/0
(10-40-)10
(K100-50)/10
(10+50)15
;
run;&lt;/PRE&gt;</description>
    <pubDate>Sat, 19 Sep 2020 13:45:54 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2020-09-19T13:45:54Z</dc:date>
    <item>
      <title>How to validate arithmetic/mathematical expressions in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-validate-arithmetic-mathematical-expressions-in-SAS/m-p/685183#M207776</link>
      <description>&lt;P&gt;I want to validate arithmetic/Mathematical expressions. expression is a string that can be given to program via any file or via datalines/cards.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
length expression $15;
input expression $;
datalines;                      
(10+5)/(10-7)
1+2
2-3/4
(6-10)*6
c-10
10+-5
10/0
(10-40-)10
(K100-50)/10
(10+50)15&lt;BR /&gt;10*/5
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;from the above expression some are correct and few are incorrect. I want to validate each expression as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is what I thought and tried&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data validation;&lt;/P&gt;&lt;P&gt;set test;&lt;/P&gt;&lt;P&gt;length validate 8;&lt;/P&gt;&lt;P&gt;validate = function(expresssion);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;function can be any macro or function that runs that executes the expression and saves the input in validate. if the value of validate is not empty than the&amp;nbsp; expression is correct else the expression is incorrect.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;validate = put(expression , 8.);&lt;BR /&gt;validate&amp;nbsp;=&amp;nbsp;expression;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but it's not working as expected.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;below is the expression validation&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;"(10+5)/(10-7)" */Correct/*&lt;BR /&gt;"1+2" */Correct/*&lt;BR /&gt;"2-3/4" */Correct/*&lt;BR /&gt;"(6-10)*6" */Correct/*&lt;BR /&gt;"c-10" */InCorrect/*&lt;BR /&gt;"10+-5" */Correct/*&lt;BR /&gt;"10/0" */InCorrect/*&lt;BR /&gt;"(10-40-)10" */InCorrect/*&lt;BR /&gt;"(K12 - 50)/10" */InCorrect/*&lt;BR /&gt;"(100+50)15" */InCorrect/*&lt;/P&gt;&lt;P&gt;"10*/5"&amp;nbsp;*/InCorrect/*&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kindly provide an approach to validate arithmetic expressions&amp;nbsp; that are stored in character variables.&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Sep 2020 09:47:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-validate-arithmetic-mathematical-expressions-in-SAS/m-p/685183#M207776</guid>
      <dc:creator>Azeem112</dc:creator>
      <dc:date>2020-09-20T09:47:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to validate arithmetic/mathematical expressions in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-validate-arithmetic-mathematical-expressions-in-SAS/m-p/685185#M207778</link>
      <description>&lt;P&gt;This could give you a clue .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data test;
length expression $15;
input expression $;
result=resolve(cats('%sysevalf(',expression,')'));
datalines;                      
(10+5)/(10-7)
1+2
2-3/4
(6-10)*6
c-10
10+-5
10/0
(10-40-)10
(K100-50)/10
(10+50)15
;
run;&lt;/PRE&gt;</description>
      <pubDate>Sat, 19 Sep 2020 13:45:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-validate-arithmetic-mathematical-expressions-in-SAS/m-p/685185#M207778</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-09-19T13:45:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to validate arithmetic/mathematical expressions in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-validate-arithmetic-mathematical-expressions-in-SAS/m-p/685205#M207782</link>
      <description>&lt;P&gt;I will beg to differ on these:&lt;/P&gt;
&lt;P&gt;"c-10" */InCorrect/*&amp;nbsp; :&amp;lt;= this would be variable C subtracting 10. Why is this incorrect?&lt;/P&gt;
&lt;P&gt;"10+-5" */InCorrect/* :&amp;lt;= this is 10 plus a negative 5&lt;/P&gt;
&lt;PRE&gt;4    data junk;
5       x = 10+-5;
6    run;

NOTE: The data set WORK.JUNK has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds

&lt;/PRE&gt;
&lt;P&gt;and yields the expected value of 5&lt;BR /&gt;&lt;BR /&gt;"(K12 - 50)/10" */InCorrect/ :&amp;lt;= variable K12 minus 50, the quantity divided by 10. So why is this incorrect. If the variable K12 is not defined then 1) just created it, 2) effectively assigned a missing value and 3) a missing value results from the expression. Note the log below shows &lt;STRONG&gt;2&lt;/STRONG&gt; variables in the output data.&lt;/P&gt;
&lt;PRE&gt;11   data junk;
12      y=(K12 - 50)/10;
13   run;

NOTE: Variable K12 is uninitialized.
NOTE: Missing values were generated as a result of performing
      an operation on missing values.
      Each place is given by:
      (Number of times) at (Line):(Column).
      1 at 12:11
NOTE: The data set WORK.JUNK has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this is for a grammar other than SAS you&amp;nbsp; need to be much more explicit about why these are incorrect, and SAS may not be the tool to evaluate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Sep 2020 17:23:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-validate-arithmetic-mathematical-expressions-in-SAS/m-p/685205#M207782</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-19T17:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to validate arithmetic/mathematical expressions in SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-validate-arithmetic-mathematical-expressions-in-SAS/m-p/685257#M207808</link>
      <description>&lt;P&gt;Regarding "C-10" and "(K12 - 50)/10" are incorrect because variables are not allowed and system don't ave values for these variables. just numeric arithmetic expression.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regarding 10+-5 is correct, I've edited the post. however 10+*5 or 10/*5 where two operators are coming together except "10+-5", "10*-5" and "10/-5" are incorrect.&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Sun, 20 Sep 2020 09:46:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-validate-arithmetic-mathematical-expressions-in-SAS/m-p/685257#M207808</guid>
      <dc:creator>Azeem112</dc:creator>
      <dc:date>2020-09-20T09:46:14Z</dc:date>
    </item>
  </channel>
</rss>

