<?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: Is there a way to check the values of a SAS char var that has numbers only? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-check-the-values-of-a-SAS-char-var-that-has/m-p/810460#M33846</link>
    <description>&lt;P&gt;Here's one way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    input x $6.;
    length x $6.;
    datalines;
12346
1a2b3c
1+abc
abcde
    ;
run;

data string_with_only_numbers;
    set have;
    if anydigit(x) and not anyalpha(x);
run;

data string_with_only_alpha;
    set have;
    if not anydigit(x) and anyalpha(x);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Courtesy of this post:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/Check-numeric-values-in-alphanumeric-variables/td-p/19247" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/Check-numeric-values-in-alphanumeric-variables/td-p/19247&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Apr 2022 19:01:17 GMT</pubDate>
    <dc:creator>mklangley</dc:creator>
    <dc:date>2022-04-28T19:01:17Z</dc:date>
    <item>
      <title>Is there a way to check the values of a SAS char var that has numbers only?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-check-the-values-of-a-SAS-char-var-that-has/m-p/810446#M33842</link>
      <description>&lt;P&gt;If a var is defined as char,&lt;/P&gt;&lt;P&gt;&amp;nbsp; length x $6.;&lt;/P&gt;&lt;P&gt;How do I check the values of this var that has numbers only?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example, if x has&lt;/P&gt;&lt;P&gt;12346&lt;/P&gt;&lt;P&gt;1a2b3c&lt;/P&gt;&lt;P&gt;1+abc&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I find numeric values such as 12346?&lt;/P&gt;&lt;P&gt;Or is there a way to look for values that's alphabets? special chars?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2022 18:33:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-check-the-values-of-a-SAS-char-var-that-has/m-p/810446#M33842</guid>
      <dc:creator>cosmid</dc:creator>
      <dc:date>2022-04-28T18:33:51Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to check the values of a SAS char var that has numbers only?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-check-the-values-of-a-SAS-char-var-that-has/m-p/810455#M33844</link>
      <description>Take a look at the ANY*/NOT* set of functions that will allow you to scan through, but they operate on each row not a column.&lt;BR /&gt;&lt;BR /&gt;ANYALPHA will check variables for any alphabetical values for example. &lt;BR /&gt;&lt;BR /&gt;Or if you're trying to convert you could just use the ?? options in INPUT&lt;BR /&gt;&lt;BR /&gt;X_num = input(x, ?? 8.);&lt;BR /&gt;&lt;BR /&gt;Which will convert anything to a valid number and suppress any warnings/messages to the log. Bit dangerous to use IMO but also has it's uses.</description>
      <pubDate>Thu, 28 Apr 2022 18:55:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-check-the-values-of-a-SAS-char-var-that-has/m-p/810455#M33844</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-04-28T18:55:03Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to check the values of a SAS char var that has numbers only?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-check-the-values-of-a-SAS-char-var-that-has/m-p/810456#M33845</link>
      <description>&lt;P&gt;An easy way to test if the value is a valid representation of a number is to try to convert it to a number.&lt;/P&gt;
&lt;P&gt;Just use the normal numeric informat.&amp;nbsp; Use the ?? modifier to suppress error messages.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  number=input(x,??32.);
  valid_number = not missing(number);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or if you want to accept strings with commas and dollar signs ( like 1,200 and $5,000) then use the COMMA informat instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If X can hold strings that are longer than 32 bytes then you might want to also test that the value is not too long.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
&amp;nbsp;&amp;nbsp;if&amp;nbsp;length(strip(x))&amp;lt;=32&amp;nbsp;then&amp;nbsp;number=input(strip(x),??32.);
&amp;nbsp;&amp;nbsp;valid_number&amp;nbsp;=&amp;nbsp;not&amp;nbsp;missing(number);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2022 18:59:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-check-the-values-of-a-SAS-char-var-that-has/m-p/810456#M33845</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-28T18:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to check the values of a SAS char var that has numbers only?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-check-the-values-of-a-SAS-char-var-that-has/m-p/810460#M33846</link>
      <description>&lt;P&gt;Here's one way:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    input x $6.;
    length x $6.;
    datalines;
12346
1a2b3c
1+abc
abcde
    ;
run;

data string_with_only_numbers;
    set have;
    if anydigit(x) and not anyalpha(x);
run;

data string_with_only_alpha;
    set have;
    if not anydigit(x) and anyalpha(x);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Courtesy of this post:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/Check-numeric-values-in-alphanumeric-variables/td-p/19247" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/Check-numeric-values-in-alphanumeric-variables/td-p/19247&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Apr 2022 19:01:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-check-the-values-of-a-SAS-char-var-that-has/m-p/810460#M33846</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2022-04-28T19:01:17Z</dc:date>
    </item>
    <item>
      <title>Re: Is there a way to check the values of a SAS char var that has numbers only?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-check-the-values-of-a-SAS-char-var-that-has/m-p/810602#M33857</link>
      <description>&lt;PRE&gt;data have;
    input x $6.;
    length x $ 6;
flag=ifn(notdigit(strip(x)),0,1);
    datalines;
12346
1a2b3c
1+abc
abcde
;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Apr 2022 12:24:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Is-there-a-way-to-check-the-values-of-a-SAS-char-var-that-has/m-p/810602#M33857</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-04-29T12:24:49Z</dc:date>
    </item>
  </channel>
</rss>

