<?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: Validate if Character is  a Number in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Validate-if-Character-is-a-Number/m-p/897644#M354734</link>
    <description>&lt;P&gt;If some of your suspect values might be currency, have thousands separators (12,345,678) or percentages you might want to use the COMMA32 informat.&lt;/P&gt;</description>
    <pubDate>Fri, 06 Oct 2023 20:04:40 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-10-06T20:04:40Z</dc:date>
    <item>
      <title>Validate if Character is  a Number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Validate-if-Character-is-a-Number/m-p/897614#M354718</link>
      <description>&lt;DIV&gt;I'm working on a data integrity check to validate if a character field only contains values that are numbers.&amp;nbsp; The goal is to populate have.isnumber with values Y or N depending on if the value is a number or not.&amp;nbsp; I caught instances where there are two decimals in the character field rather than one.&amp;nbsp; E.g. 3..14 instead of 3.14.&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;Is there a way to flag this in a data step?&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;proc sql;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; create table have&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; (&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; characterField varchar2(10)&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; );&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; insert into have (characterField) values ('3.22');&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;insert into have (characterField) values ('4..22');&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; insert into have (characterField) values ('N/A');&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;quit;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;data want; set have;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if characterField = '3.22' then IsNumber = 'Y';&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if characterField = '4..22' then IsNumber = 'N';&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if characterField = 'N/A' then IsNumber = 'N';&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;</description>
      <pubDate>Fri, 06 Oct 2023 17:14:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Validate-if-Character-is-a-Number/m-p/897614#M354718</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2023-10-06T17:14:39Z</dc:date>
    </item>
    <item>
      <title>Re: Validate if Character is  a Number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Validate-if-Character-is-a-Number/m-p/897621#M354721</link>
      <description>&lt;P&gt;My approach would be:&lt;/P&gt;
&lt;PRE&gt;data example;
  input characterfield $;
  isnumber = not missing(input(characterfield,?? 32.));
datalines;
3.22
4..2
N/A
1.23e7
;&lt;/PRE&gt;
&lt;P&gt;Which gets 1 for is a number or 0 for not. I really dislike character Y/N as pretty much requires an if/then to assign and is much harder to count for reporting. Assign a custom format that will show Y for 1 and N for 0 if needed for boss.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The ?? in the INPUT function call suppresses invalid data messages that would otherwise appear in the log for the N/A and 4..2 and similar.&lt;/P&gt;
&lt;P&gt;Note that I included a scientific notation to show that SAS will accept such as a number. If you have things that might look like that and should not be a number then the problem needs some expansion in description.&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/5059"&gt;@DavidPhillips2&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;DIV&gt;I'm working on a data integrity check to validate if a character field only contains values that are numbers.&amp;nbsp; The goal is to populate have.isnumber with values Y or N depending on if the value is a number or not.&amp;nbsp; I caught instances where there are two decimals in the character field rather than one.&amp;nbsp; E.g. 3..14 instead of 3.14.&amp;nbsp;&amp;nbsp;&lt;SPAN&gt;Is there a way to flag this in a data step?&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;proc sql;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; create table have&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; (&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; characterField varchar2(10)&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; );&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; insert into have (characterField) values ('3.22');&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt;insert into have (characterField) values ('4..22');&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; insert into have (characterField) values ('N/A');&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;quit;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;data want; set have;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if characterField = '3.22' then IsNumber = 'Y';&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if characterField = '4..22' then IsNumber = 'N';&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if characterField = 'N/A' then IsNumber = 'N';&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2023 17:35:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Validate-if-Character-is-a-Number/m-p/897621#M354721</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-10-06T17:35:32Z</dc:date>
    </item>
    <item>
      <title>Re: Validate if Character is  a Number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Validate-if-Character-is-a-Number/m-p/897622#M354722</link>
      <description>&lt;P&gt;Thanks for the one-line solution.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2023 17:40:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Validate-if-Character-is-a-Number/m-p/897622#M354722</guid>
      <dc:creator>DavidPhillips2</dc:creator>
      <dc:date>2023-10-06T17:40:23Z</dc:date>
    </item>
    <item>
      <title>Re: Validate if Character is  a Number</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Validate-if-Character-is-a-Number/m-p/897644#M354734</link>
      <description>&lt;P&gt;If some of your suspect values might be currency, have thousands separators (12,345,678) or percentages you might want to use the COMMA32 informat.&lt;/P&gt;</description>
      <pubDate>Fri, 06 Oct 2023 20:04:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Validate-if-Character-is-a-Number/m-p/897644#M354734</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-10-06T20:04:40Z</dc:date>
    </item>
  </channel>
</rss>

