<?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: Covert char to numeric in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Covert-char-to-numeric/m-p/771615#M244905</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Would you also have cases of &amp;gt;= or &amp;lt;= or other symbols that need to be accounted for in this situation?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/331278"&gt;@rajd1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I have a character variable that needs to be converted to numeric. The character &amp;lt;0.001 needs to be converted to 0.001 numeric value.&lt;/P&gt;
&lt;P&gt;Data Have:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input iD nums $;
cards;
1	1.675	
2	&amp;lt;0.001	
3	3.578	
4	&amp;lt;0.00001
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;One way might be:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  newnum=input(compress(nums, "+-.", "kd"),12.);
run;&lt;/PRE&gt;
&lt;P&gt;The compress function removes everything except the + - decimal point and digits (the d option indicates digits, the k keeps instead of removing. Then input converts to numeric. This assumes you don't have more than 12 characters in the resulting numeric value string.&lt;/P&gt;
&lt;P&gt;Warning: if for some reason you have exponential notation values such as 1.5E3 in the data the E gets removed and the result would be a missing value. If that is the case you need to check for the presence of the E and treat that string differently (add E to the list of characters "+-.eE" for example)&lt;/P&gt;</description>
    <pubDate>Fri, 01 Oct 2021 15:57:29 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-10-01T15:57:29Z</dc:date>
    <item>
      <title>Covert char to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Covert-char-to-numeric/m-p/771605#M244898</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I have a character variable that needs to be converted to numeric. The character &amp;lt;0.001 needs to be converted to 0.001 numeric value.&lt;/P&gt;
&lt;P&gt;Data Have:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input iD nums $;
cards;
1	1.675	
2	&amp;lt;0.001	
3	3.578	
4	&amp;lt;0.00001
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Oct 2021 15:41:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Covert-char-to-numeric/m-p/771605#M244898</guid>
      <dc:creator>rajd1</dc:creator>
      <dc:date>2021-10-01T15:41:01Z</dc:date>
    </item>
    <item>
      <title>Re: Covert char to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Covert-char-to-numeric/m-p/771606#M244899</link>
      <description>&lt;P&gt;Would you also have cases of &amp;gt;= or &amp;lt;= or other symbols that need to be accounted for in this situation?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/331278"&gt;@rajd1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I have a character variable that needs to be converted to numeric. The character &amp;lt;0.001 needs to be converted to 0.001 numeric value.&lt;/P&gt;
&lt;P&gt;Data Have:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input iD nums $;
cards;
1	1.675	
2	&amp;lt;0.001	
3	3.578	
4	&amp;lt;0.00001
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Oct 2021 15:42:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Covert-char-to-numeric/m-p/771606#M244899</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-01T15:42:41Z</dc:date>
    </item>
    <item>
      <title>Re: Covert char to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Covert-char-to-numeric/m-p/771609#M244900</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;P&gt;Yes, there might be &amp;lt; or &amp;gt; &amp;lt;= or &amp;gt;=&lt;/P&gt;</description>
      <pubDate>Fri, 01 Oct 2021 15:44:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Covert-char-to-numeric/m-p/771609#M244900</guid>
      <dc:creator>rajd1</dc:creator>
      <dc:date>2021-10-01T15:44:41Z</dc:date>
    </item>
    <item>
      <title>Re: Covert char to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Covert-char-to-numeric/m-p/771610#M244901</link>
      <description>Always at the beginning?</description>
      <pubDate>Fri, 01 Oct 2021 15:45:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Covert-char-to-numeric/m-p/771610#M244901</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-01T15:45:48Z</dc:date>
    </item>
    <item>
      <title>Re: Covert char to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Covert-char-to-numeric/m-p/771614#M244904</link>
      <description>&lt;P&gt;What will work depends on your data. If you're sure that there can't be numbers in scientific notation then the derivation syntax for&amp;nbsp;&lt;CODE class=" language-sas"&gt;nums_new_1&lt;/CODE&gt;&amp;nbsp;should be suitable.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input iD nums $;
  cards;
1 1.675 
2 &amp;lt;0.001  
3 3.578 
4 &amp;lt;0.00001
;

data want;
  set have;
  nums_new_1=input(compress(nums,'.+-','kd'),best32.);
  nums_new_2=input(compress(nums,'&amp;lt;=&amp;gt; '),best32.);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Oct 2021 16:02:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Covert-char-to-numeric/m-p/771614#M244904</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-10-01T16:02:32Z</dc:date>
    </item>
    <item>
      <title>Re: Covert char to numeric</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Covert-char-to-numeric/m-p/771615#M244905</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Would you also have cases of &amp;gt;= or &amp;lt;= or other symbols that need to be accounted for in this situation?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/331278"&gt;@rajd1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I have a character variable that needs to be converted to numeric. The character &amp;lt;0.001 needs to be converted to 0.001 numeric value.&lt;/P&gt;
&lt;P&gt;Data Have:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input iD nums $;
cards;
1	1.675	
2	&amp;lt;0.001	
3	3.578	
4	&amp;lt;0.00001
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;One way might be:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  newnum=input(compress(nums, "+-.", "kd"),12.);
run;&lt;/PRE&gt;
&lt;P&gt;The compress function removes everything except the + - decimal point and digits (the d option indicates digits, the k keeps instead of removing. Then input converts to numeric. This assumes you don't have more than 12 characters in the resulting numeric value string.&lt;/P&gt;
&lt;P&gt;Warning: if for some reason you have exponential notation values such as 1.5E3 in the data the E gets removed and the result would be a missing value. If that is the case you need to check for the presence of the E and treat that string differently (add E to the list of characters "+-.eE" for example)&lt;/P&gt;</description>
      <pubDate>Fri, 01 Oct 2021 15:57:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Covert-char-to-numeric/m-p/771615#M244905</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-10-01T15:57:29Z</dc:date>
    </item>
  </channel>
</rss>

