<?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 to Numeric in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric/m-p/730778#M227601</link>
    <description>&lt;P&gt;BEST is just an alias for the normal numeric informat.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that if the width of the INFORMAT specification is shorter than the length of the string being read the extra characters in the string are ignored.&amp;nbsp; But the INPUT() function does not mind if the width of the informat specification is longer than the length of the string being read.&amp;nbsp; So frequently is safer to just go ahead and code the maximum width the informat supports.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;numeric = input(column1,??32.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the strings might also contain commas, dollar signs, percent signs a parentheses and you also want to convert those strings to the numbers they represent then use the COMMA (or perhaps COMMAX) informat instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;numeric = input(column1,??comma32.);&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So in many situations the COMMA informat a better "BEST" informat than the normal&amp;nbsp; w. informat that the BEST informat is aliased to.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 01 Apr 2021 16:38:22 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-04-01T16:38:22Z</dc:date>
    <item>
      <title>Character to Numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric/m-p/730743#M227580</link>
      <description>Hi experts,&lt;BR /&gt;I came across a sample dataset where I want to convert character to numeric ones.&lt;BR /&gt;&lt;BR /&gt;The sample datasets contains&lt;BR /&gt;&lt;BR /&gt;The datasets what I have&lt;BR /&gt;Column 1&lt;BR /&gt;345&lt;BR /&gt;A56&lt;BR /&gt;450&lt;BR /&gt;124&lt;BR /&gt;567&lt;BR /&gt;R45&lt;BR /&gt;&lt;BR /&gt;The column variable is character... I want to convert to numeric... but The condition is if any one of the variable contains character it should me missing&lt;BR /&gt;&lt;BR /&gt;The dataset what I want&lt;BR /&gt;Column (Numeric)&lt;BR /&gt;345&lt;BR /&gt;&lt;BR /&gt;450&lt;BR /&gt;124&lt;BR /&gt;567&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Please help me to overcome this problem&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;TIA</description>
      <pubDate>Thu, 01 Apr 2021 15:29:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric/m-p/730743#M227580</guid>
      <dc:creator>Pooja98</dc:creator>
      <dc:date>2021-04-01T15:29:02Z</dc:date>
    </item>
    <item>
      <title>Re: Character to Numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric/m-p/730745#M227582</link>
      <description>&lt;P&gt;You have to create a new variable for the numeric, as you can't change a variable from character to numeric.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    numeric = input(column1,3.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Apr 2021 15:34:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric/m-p/730745#M227582</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-04-01T15:34:50Z</dc:date>
    </item>
    <item>
      <title>Re: Character to Numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric/m-p/730750#M227587</link>
      <description>How can I remove those observation which contain character&lt;BR /&gt;</description>
      <pubDate>Thu, 01 Apr 2021 15:38:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric/m-p/730750#M227587</guid>
      <dc:creator>Pooja98</dc:creator>
      <dc:date>2021-04-01T15:38:05Z</dc:date>
    </item>
    <item>
      <title>Re: Character to Numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric/m-p/730751#M227588</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/305675"&gt;@Pooja98&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;How can I remove those observation which contain character&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Do you mean delete them from the data set? What does this have to do with your original question which is converting to numeric?&lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 15:39:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric/m-p/730751#M227588</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-04-01T15:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: Character to Numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric/m-p/730753#M227589</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/305675"&gt;@Pooja98&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;How can I remove those observation which contain character&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If the value, such a A53, cannot be converted to numeric by the informat used you will get 1) invalid data messages in the log and 2) a missing value as a result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or are you changing the requirement from the first post? Which was " if any one of the variable contains character it should me missing"?&lt;/P&gt;
&lt;P&gt;Delete means remove the entire record.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 15:43:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric/m-p/730753#M227589</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-04-01T15:43:47Z</dc:date>
    </item>
    <item>
      <title>Re: Character to Numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric/m-p/730759#M227592</link>
      <description>&lt;P&gt;You're describing the default behaviour for the INPUT() function. If it cannot be converted to a numeric value it will be set to missing by and an NOTE message will be in the log. &lt;BR /&gt;&lt;BR /&gt;You can suppress those notes or check for alphabetical characters with the ANYALPHA function.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if NOT anyalpha(column1) then new_numeric_variable = input(column1, 8.);
else call missing(new_numeric_variable);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Except you don't need the ELSE because that's SAS default. &lt;BR /&gt;So it can become:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if NOT anyalpha(column1) then new_numeric_variable = input(column1, 8.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;Now, there's also an option to suppress the NOTES within the INPUT function, ?? so you can change it to be:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new_numeric_variable = input(column1, ?? 8.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;All the solutions above will give you the desired output, the last is the simplest.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 19:15:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric/m-p/730759#M227592</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-04-01T19:15:33Z</dc:date>
    </item>
    <item>
      <title>Re: Character to Numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric/m-p/730774#M227597</link>
      <description>&lt;P&gt;Use the ?? modifier for the BEST. informat:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input column1 $;
datalines;
345
A56
450
124
567
R45
;

data want;
set have;
numeric = input(column1,??best.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 01 Apr 2021 16:22:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric/m-p/730774#M227597</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-04-01T16:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: Character to Numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric/m-p/730778#M227601</link>
      <description>&lt;P&gt;BEST is just an alias for the normal numeric informat.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that if the width of the INFORMAT specification is shorter than the length of the string being read the extra characters in the string are ignored.&amp;nbsp; But the INPUT() function does not mind if the width of the informat specification is longer than the length of the string being read.&amp;nbsp; So frequently is safer to just go ahead and code the maximum width the informat supports.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;numeric = input(column1,??32.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If the strings might also contain commas, dollar signs, percent signs a parentheses and you also want to convert those strings to the numbers they represent then use the COMMA (or perhaps COMMAX) informat instead.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;numeric = input(column1,??comma32.);&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So in many situations the COMMA informat a better "BEST" informat than the normal&amp;nbsp; w. informat that the BEST informat is aliased to.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Apr 2021 16:38:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Character-to-Numeric/m-p/730778#M227601</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-04-01T16:38:22Z</dc:date>
    </item>
  </channel>
</rss>

