<?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: Character expression conversion to numeric result in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Character-expression-conversion-to-numeric-result/m-p/762312#M241342</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393800"&gt;@Anthony_de_Fex&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Also something not involving macros.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;A pointless limitation. Why do you want to avoid macros?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(And technically, no one has proposed a &lt;EM&gt;macro&lt;/EM&gt; solution; what has been proposed is a solution using a macro variable, which is not the same as a macro; or using a macro function %sysevalf, which is not the same as a macro)&lt;/P&gt;</description>
    <pubDate>Wed, 18 Aug 2021 15:24:41 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2021-08-18T15:24:41Z</dc:date>
    <item>
      <title>Character expression conversion to numeric result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-expression-conversion-to-numeric-result/m-p/762288#M241329</link>
      <description>&lt;P&gt;I was curious to know if there is some sas function that can convert a value of a character variable ("1/3"), to a numeric variable (.333333...). This would save me the trouble of parsing out the different parts of "1/3" into intermediate variables to then use conditional statements to do the calculation.&amp;nbsp;&lt;/P&gt;&lt;P&gt;It would be nice if input("1/3",8.) would give you .33333&lt;/P&gt;</description>
      <pubDate>Wed, 18 Aug 2021 14:49:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-expression-conversion-to-numeric-result/m-p/762288#M241329</guid>
      <dc:creator>Anthony_de_Fex</dc:creator>
      <dc:date>2021-08-18T14:49:33Z</dc:date>
    </item>
    <item>
      <title>Re: Character expression conversion to numeric result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-expression-conversion-to-numeric-result/m-p/762297#M241332</link>
      <description>&lt;P&gt;Not aware of an Informat, which would be the likely took, that would do this.&lt;/P&gt;
&lt;P&gt;If the data is "clean" the parse and calculate in pretty simple:&lt;/P&gt;
&lt;PRE&gt;data example;
   input x $;
   if index(x,'/')&amp;gt;0 then number = input(scan(x,1,'/'),12.)/input(scan(x,2,'/'),12.);
datalines;
1/3
10/31
4.5
3.555/17.44
;&lt;/PRE&gt;
&lt;P&gt;The above only does the division when there is a / and a non-fraction value is provided to demonstrate that.&lt;/P&gt;
&lt;P&gt;If you have more than one / in the string you're on your own.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Aug 2021 15:04:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-expression-conversion-to-numeric-result/m-p/762297#M241332</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-18T15:04:57Z</dc:date>
    </item>
    <item>
      <title>Re: Character expression conversion to numeric result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-expression-conversion-to-numeric-result/m-p/762302#M241335</link>
      <description>&lt;P&gt;If the character string is a syntactically correct statement, put it into a macro variable, and then after that in a DATA step you can do&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;input(&amp;amp;macrovarname,best16.)&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Aug 2021 15:11:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-expression-conversion-to-numeric-result/m-p/762302#M241335</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-08-18T15:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: Character expression conversion to numeric result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-expression-conversion-to-numeric-result/m-p/762306#M241337</link>
      <description>&lt;P&gt;thanks, but I was curious to know if there is an easier way than that. Something specifically designed to resolve all manner of arithmetic formulas that could be in a character variable. Some one function like the input function. Also something not involving macros.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Aug 2021 15:14:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-expression-conversion-to-numeric-result/m-p/762306#M241337</guid>
      <dc:creator>Anthony_de_Fex</dc:creator>
      <dc:date>2021-08-18T15:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: Character expression conversion to numeric result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-expression-conversion-to-numeric-result/m-p/762311#M241341</link>
      <description>&lt;P&gt;No.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IF the string is just pure arithmetic, like your example, then you could use %sysevalf() macro function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input equation $20.;
cards;
1/3
1+1/2
;

data want;
  set have;
  number=input(resolve(cats('%sysevalf(',equation,')')),32.);
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs    equation     number

 1      1/3        0.33333
 2      1+1/2      1.50000
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;If you also have other strings that might be numbers you might also try using the COMMA informat (the "best" informat).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input equation $20.;
cards;
1/3
1+1/2
25%
1,234
;

data want;
  set have;
  number=input(equation,??comma32.);
  if missing(number) then 
    number=input(resolve(cats('%sysevalf(',equation,')')),32.)
  ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 18 Aug 2021 15:22:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-expression-conversion-to-numeric-result/m-p/762311#M241341</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-18T15:22:58Z</dc:date>
    </item>
    <item>
      <title>Re: Character expression conversion to numeric result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-expression-conversion-to-numeric-result/m-p/762312#M241342</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393800"&gt;@Anthony_de_Fex&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Also something not involving macros.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;A pointless limitation. Why do you want to avoid macros?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(And technically, no one has proposed a &lt;EM&gt;macro&lt;/EM&gt; solution; what has been proposed is a solution using a macro variable, which is not the same as a macro; or using a macro function %sysevalf, which is not the same as a macro)&lt;/P&gt;</description>
      <pubDate>Wed, 18 Aug 2021 15:24:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-expression-conversion-to-numeric-result/m-p/762312#M241342</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-08-18T15:24:41Z</dc:date>
    </item>
    <item>
      <title>Re: Character expression conversion to numeric result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-expression-conversion-to-numeric-result/m-p/762318#M241346</link>
      <description>&lt;P&gt;Thanks. Something like this is what I was interested in. I don't have anything against macros or macro variables. I want the formulas to be values in a dataset variable, not in a macro variable.&lt;/P&gt;&lt;P&gt;I was just wondering about a unit conversion dataset I was recently looking at. Some of the factors may be truncated decimals from the division of two numbers where the decimals go on to infinity. I was wondering if instead of specifying the truncated result, to just put in the formula and have sas figure out what it resolves to.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Aug 2021 15:41:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-expression-conversion-to-numeric-result/m-p/762318#M241346</guid>
      <dc:creator>Anthony_de_Fex</dc:creator>
      <dc:date>2021-08-18T15:41:37Z</dc:date>
    </item>
    <item>
      <title>Re: Character expression conversion to numeric result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-expression-conversion-to-numeric-result/m-p/762319#M241347</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try this:&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data Test;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;informat String $10.;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;input String;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Position = findc(String,'/');&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;if Position then do;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;put _all_;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Numerator = substr(String,1,Position-1);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Denominator = substr(String,Position+1);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Number = input (Numerator,10.) / input(Denominator,10.);&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;end;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;else number = input(String,10.); &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;datalines;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;1/3&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;2/5&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;8&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;title "Listing of Test";&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;proc print data=Test;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif"&gt;Please check out support.sas.com/Cody to see some of my SAS programming books.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Aug 2021 15:47:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-expression-conversion-to-numeric-result/m-p/762319#M241347</guid>
      <dc:creator>Ron_Cody</dc:creator>
      <dc:date>2021-08-18T15:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: Character expression conversion to numeric result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-expression-conversion-to-numeric-result/m-p/762322#M241349</link>
      <description>&lt;P&gt;Hi Ron. Thanks for your answer, but that is too much for what I had in mind. I like the&amp;nbsp;input(resolve(cats('%sysevalf(',equation,')')),32.); from the other user.&lt;/P&gt;&lt;P&gt;I've read some of your books by the way, like 20 years ago.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Aug 2021 15:53:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-expression-conversion-to-numeric-result/m-p/762322#M241349</guid>
      <dc:creator>Anthony_de_Fex</dc:creator>
      <dc:date>2021-08-18T15:53:16Z</dc:date>
    </item>
    <item>
      <title>Re: Character expression conversion to numeric result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-expression-conversion-to-numeric-result/m-p/762323#M241350</link>
      <description>Hi.&lt;BR /&gt;&lt;BR /&gt;Glad to hear you have read some of my books. I like simple coding, that&lt;BR /&gt;%syseval is too complicated for me! I have two new books using SAS Studio&lt;BR /&gt;with OnDemand for Academics. I have become a huge fan of OnDemand and&lt;BR /&gt;Studio.&lt;BR /&gt;&lt;BR /&gt;Best,&lt;BR /&gt;Ron&lt;BR /&gt;</description>
      <pubDate>Wed, 18 Aug 2021 16:01:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-expression-conversion-to-numeric-result/m-p/762323#M241350</guid>
      <dc:creator>Ron_Cody</dc:creator>
      <dc:date>2021-08-18T16:01:23Z</dc:date>
    </item>
    <item>
      <title>Re: Character expression conversion to numeric result</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-expression-conversion-to-numeric-result/m-p/762330#M241353</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393800"&gt;@Anthony_de_Fex&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks. Something like this is what I was interested in. I don't have anything against macros or macro variables. I want the formulas to be values in a dataset variable, not in a macro variable.&lt;/P&gt;
&lt;P&gt;I was just wondering about a unit conversion dataset I was recently looking at. Some of the factors may be truncated decimals from the division of two numbers where the decimals go on to infinity. I was wondering if instead of specifying the truncated result, to just put in the formula and have sas figure out what it resolves to.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You might look in the documentation of Proc Format that uses a formula stored in a function created by Proc Fcmp to do unit conversions. The example in the documentation shows a Fahrenheit to Celsius and vice versa temperature conversion. These allow putting the division as 1/3 if needed as the Fcmp function would use typical syntax for numeric computation. If the conversion has ranges involved the functions allow testing one or more of the parameters passed to execute the appropriate section of code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/p1gg77jyhc9s42n1f1vjyx2hsg8b.htm" target="_blank"&gt;https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/proc/p1gg77jyhc9s42n1f1vjyx2hsg8b.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Caveat: If you use these formats you need to make the functions and the formats available to the SAS session. Also do not lose the code to create them. You will likely need to rebuild both the function and the format in later versions of SAS as the format catalog alone may not be sufficient in later software.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Aug 2021 16:24:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-expression-conversion-to-numeric-result/m-p/762330#M241353</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-18T16:24:07Z</dc:date>
    </item>
  </channel>
</rss>

