<?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: Convert Character to Numeric in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Convert-Character-to-Numeric/m-p/99414#M9641</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How about?:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input RESULT &amp;amp; $20.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;172&lt;/P&gt;&lt;P&gt;1.83&lt;/P&gt;&lt;P&gt;NEGATIVE&lt;/P&gt;&lt;P&gt;&amp;lt; 2&lt;/P&gt;&lt;P&gt;+++&lt;/P&gt;&lt;P&gt;&amp;gt; 25&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; NEW_RSLT=input(compress(result," &amp;lt;&amp;gt;"), ?? 12.);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 05 Apr 2013 19:53:20 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2013-04-05T19:53:20Z</dc:date>
    <item>
      <title>Convert Character to Numeric</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Convert-Character-to-Numeric/m-p/99413#M9640</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a character field that has values as found in RESULT.&amp;nbsp; I want to convert numbers to a numeric variable (if there is an inequality, then I just truncate the inequality sign).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" height="149" jive-data-cell="{&amp;quot;color&amp;quot;:&amp;quot;#000000&amp;quot;,&amp;quot;textAlign&amp;quot;:&amp;quot;left&amp;quot;,&amp;quot;padding&amp;quot;:&amp;quot;2&amp;quot;}" jive-data-header="{&amp;quot;color&amp;quot;:&amp;quot;#FFFFFF&amp;quot;,&amp;quot;backgroundColor&amp;quot;:&amp;quot;#6690BC&amp;quot;,&amp;quot;textAlign&amp;quot;:&amp;quot;center&amp;quot;,&amp;quot;padding&amp;quot;:&amp;quot;2&amp;quot;,&amp;quot;fontFamily&amp;quot;:&amp;quot;arial,helvetica,sans-serif&amp;quot;}" style="border: 1px solid rgb(0, 0, 0); width: 71px; height: 134px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;RESULT&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;NEW_RSLT&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;172&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: right;"&gt;172&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px; text-align: left;"&gt;1.83&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: right;"&gt;1.83&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px; text-align: right;"&gt;NEGATIVE&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: right;"&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px; text-align: left;"&gt;&amp;lt; 2&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: right;"&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px; text-align: left;"&gt;+++&lt;/TD&gt;&lt;TD style="padding: 2px; text-align: right;"&gt;.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="text-align: left;"&gt;&amp;gt; 25&lt;/TD&gt;&lt;TD style="text-align: right;"&gt;25&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is a VERY small sample of values.&amp;nbsp; There are all kinds of alpha/numeric/punctuation results (some are even mixed).&amp;nbsp; Here is what I have attempted:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; anyalpha(result)=&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; &amp;amp; anypunct(result)=&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;then&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; new_rslt=input(compress(result,&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: purple; background: white;"&gt;' &amp;lt;&amp;gt;'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: teal; background: white;"&gt;best.&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This does not work because '&amp;lt;' and '&amp;gt;' are excluded in the ANYPUNT() function.&amp;nbsp; Second, a period is also&amp;nbsp; excluded, so it never converts 1.83 to a number.&amp;nbsp; Any suggestions on how to work around this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Apr 2013 19:30:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Convert-Character-to-Numeric/m-p/99413#M9640</guid>
      <dc:creator>djbateman</dc:creator>
      <dc:date>2013-04-05T19:30:50Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Character to Numeric</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Convert-Character-to-Numeric/m-p/99414#M9641</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How about?:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input RESULT &amp;amp; $20.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; cards;&lt;/P&gt;&lt;P&gt;172&lt;/P&gt;&lt;P&gt;1.83&lt;/P&gt;&lt;P&gt;NEGATIVE&lt;/P&gt;&lt;P&gt;&amp;lt; 2&lt;/P&gt;&lt;P&gt;+++&lt;/P&gt;&lt;P&gt;&amp;gt; 25&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; NEW_RSLT=input(compress(result," &amp;lt;&amp;gt;"), ?? 12.);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Apr 2013 19:53:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Convert-Character-to-Numeric/m-p/99414#M9641</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2013-04-05T19:53:20Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Character to Numeric</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/Convert-Character-to-Numeric/m-p/99415#M9642</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, a starting point would be this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;new_rslt = input(result, ?? 12.);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It will find all the values that are numeric already, including scientific notation.&amp;nbsp; To get the rest, you're probably looking at the COMPRESS function first.&amp;nbsp; Here's an initial attempt:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if new_rslt = . then new_rslt = (input(compress(result,,'kd'), ??12.);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;By omitting the second parameter and specifying the third, COMPRESS is K=Keeping the D=Digits.&amp;nbsp; That's obviously not good enough since you will want decimal points, possibly a minus sign as well.&amp;nbsp; There may be ways to add to the third parameter of the COMPRESS function to get exactly what you want, or you may be able to specify your own list:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if new_rslt = . then new_rslt = input( compress(result, '-.+', 'kd'), ??12.);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I suspect this is where you will end up.&amp;nbsp; It keeps digits, as well as a decimal point, plus sign, or minus sign.&amp;nbsp; You could start here, and forget about "if new_rslt = ." since the only reason to go through the first test is to capture scientific notation.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note that this will reject a range.&amp;nbsp; 2 - 5 will not come out as 25, but will come out as missing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Apr 2013 19:55:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/Convert-Character-to-Numeric/m-p/99415#M9642</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2013-04-05T19:55:06Z</dc:date>
    </item>
  </channel>
</rss>

