<?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: check if char var has only numbers in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/check-if-char-var-has-only-numbers/m-p/968509#M376592</link>
    <description>&lt;P&gt;You can also use the&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/pgmmvacdc/9.4/lefunctionsref/p1m0n4833qyto5n1e793r44uuozv.htm" target="_self"&gt;NOTDIGIT Function&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 10 Jun 2025 11:00:37 GMT</pubDate>
    <dc:creator>Kathryn_SAS</dc:creator>
    <dc:date>2025-06-10T11:00:37Z</dc:date>
    <item>
      <title>check if char var has only numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-char-var-has-only-numbers/m-p/968499#M376587</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to create a binary variable that check if char var contain only numbers.&lt;/P&gt;
&lt;P&gt;I saw this code in google search&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;isnumber = not missing(input(X_Char,?? 32.));&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;and&amp;nbsp;I&amp;nbsp;want&amp;nbsp;to&amp;nbsp;understand&amp;nbsp;it&amp;nbsp;please.&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;What&amp;nbsp;is&amp;nbsp;the&amp;nbsp;meaning&amp;nbsp;of&amp;nbsp;??&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;I&amp;nbsp;see&amp;nbsp;that&amp;nbsp;also&amp;nbsp;this&amp;nbsp;code&amp;nbsp;work&amp;nbsp;well&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;isnumber = not missing(input(X_Char,best.));&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input X_Char $;
isnumber = not missing(input(X_Char,?? 32.));
datalines;
3.22
4..2
N/A
1.23e7
(a1) 1234
(a2) 2000
8000
Good
;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 10 Jun 2025 04:46:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-char-var-has-only-numbers/m-p/968499#M376587</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2025-06-10T04:46:49Z</dc:date>
    </item>
    <item>
      <title>Re: check if char var has only numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-char-var-has-only-numbers/m-p/968502#M376590</link>
      <description>&lt;P&gt;Maxim 1 — Read the Documentation&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/doc/en/pgmmvacdc/9.4/lefunctionsref/p19en16vskd2vhn1vwmxpxnglxxs.htm" target="_self"&gt;INPUT function documentation&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jun 2025 07:50:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-char-var-has-only-numbers/m-p/968502#M376590</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-06-10T07:50:38Z</dc:date>
    </item>
    <item>
      <title>Re: check if char var has only numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-char-var-has-only-numbers/m-p/968509#M376592</link>
      <description>&lt;P&gt;You can also use the&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/pgmmvacdc/9.4/lefunctionsref/p1m0n4833qyto5n1e793r44uuozv.htm" target="_self"&gt;NOTDIGIT Function&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jun 2025 11:00:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-char-var-has-only-numbers/m-p/968509#M376592</guid>
      <dc:creator>Kathryn_SAS</dc:creator>
      <dc:date>2025-06-10T11:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: check if char var has only numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-char-var-has-only-numbers/m-p/968513#M376596</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13770"&gt;@Kathryn_SAS&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;You can also use the&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/pgmmvacdc/9.4/lefunctionsref/p1m0n4833qyto5n1e793r44uuozv.htm" target="_self"&gt;NOTDIGIT Function&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes I thought of that, but NOTDIGIT fails for a character string like 3.22&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jun 2025 12:22:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-char-var-has-only-numbers/m-p/968513#M376596</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-06-10T12:22:31Z</dc:date>
    </item>
    <item>
      <title>Re: check if char var has only numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-char-var-has-only-numbers/m-p/968516#M376597</link>
      <description>Good point and catch.</description>
      <pubDate>Tue, 10 Jun 2025 12:48:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-char-var-has-only-numbers/m-p/968516#M376597</guid>
      <dc:creator>Kathryn_SAS</dc:creator>
      <dc:date>2025-06-10T12:48:49Z</dc:date>
    </item>
    <item>
      <title>Re: check if char var has only numbers</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-char-var-has-only-numbers/m-p/968517#M376598</link>
      <description>&lt;P&gt;The ? and ?? modifiers suppress error messages.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;32 is the maximum number of characters that the normal numeric informat can handle.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But if you don't specify the width to use for an informat then SAS will default to 12.&amp;nbsp; So your two statements are not equivalent as the first one reads the first 32 bytes of the character variable and the second only the first 12.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that BEST is the name of a &lt;STRONG&gt;FORMAT&lt;/STRONG&gt; that tries to find the best way to represent a number in a fixed number of characters.&amp;nbsp; There is no equivalent meaning of the best way to represent a number as a number so using BEST as the name of an informat is just confusing.&amp;nbsp; If you do use it that way then SAS will just take at as an alias for the normal numeric informat, the one you used in your first statement.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could try checking if the string only contains digits.&amp;nbsp; Or perhaps digits and period.&amp;nbsp; Or perhaps also include hyphen and plus sign.&amp;nbsp; But that would yield false positives for values with multiple periods. And it would yield false negatives for values in scientific notation. Note that the BEST format will generate strings in scientific notation when it has to.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One thing you might want to consider is using the COMMA (or perhaps COMMAX) informat instead or the normal numeric informat.&amp;nbsp; That will accept strings with commas in them (and also dollar signs).&lt;/P&gt;</description>
      <pubDate>Tue, 10 Jun 2025 13:14:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-char-var-has-only-numbers/m-p/968517#M376598</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-06-10T13:14:35Z</dc:date>
    </item>
  </channel>
</rss>

