<?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 Select variables with only numerical data select numbers with certain number of digits in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/Select-variables-with-only-numerical-data-select-numbers-with/m-p/698962#M9485</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with one column named "EAN". The data is not cleaned beforehand and I want to clean it by selecting all the valid ones I would like to keep and creating a new table for the output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This EAN column is a character type column as for now and is containing all kinds of unformatted characters and numbers (like 0098652312313, 00006231, 446723, abc123def, 123abc445566, etc.). What I want to keep are the variables that contain numerical data ONLY. That means I want to EXCLUDE whatever variables that contain any characters other than numbers (like abc123def and 123abc445566 I just mentioned). The output shall thus only include numbers and created as a new table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In fact, to keep a record, I also want to keep the original table but now adding a new column "FLAG". FLAG invalid data I just excluded from my new table as 1, and flag the data I just kept in the new table as 0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then, from the new table, I want to select all EAN that have EITHER 8, 12, 13, OR 14 digits (including the 0s if there's any). For example, the data 0098652312313&amp;nbsp;is seen as a 13-digital number and shall be selected, and&amp;nbsp;446723 is a 6-digital number and shall be excluded. I don't know which function I should use to select numbers that have a certain number of digits only. Hope there's a function in SAS that you could kindly teach me to solve this problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm a new learner and would really appreciate a detailed answer. Thanks a lot if you can help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 15 Nov 2020 14:44:44 GMT</pubDate>
    <dc:creator>C_L</dc:creator>
    <dc:date>2020-11-15T14:44:44Z</dc:date>
    <item>
      <title>Select variables with only numerical data select numbers with certain number of digits</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Select-variables-with-only-numerical-data-select-numbers-with/m-p/698962#M9485</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with one column named "EAN". The data is not cleaned beforehand and I want to clean it by selecting all the valid ones I would like to keep and creating a new table for the output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This EAN column is a character type column as for now and is containing all kinds of unformatted characters and numbers (like 0098652312313, 00006231, 446723, abc123def, 123abc445566, etc.). What I want to keep are the variables that contain numerical data ONLY. That means I want to EXCLUDE whatever variables that contain any characters other than numbers (like abc123def and 123abc445566 I just mentioned). The output shall thus only include numbers and created as a new table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In fact, to keep a record, I also want to keep the original table but now adding a new column "FLAG". FLAG invalid data I just excluded from my new table as 1, and flag the data I just kept in the new table as 0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then, from the new table, I want to select all EAN that have EITHER 8, 12, 13, OR 14 digits (including the 0s if there's any). For example, the data 0098652312313&amp;nbsp;is seen as a 13-digital number and shall be selected, and&amp;nbsp;446723 is a 6-digital number and shall be excluded. I don't know which function I should use to select numbers that have a certain number of digits only. Hope there's a function in SAS that you could kindly teach me to solve this problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm a new learner and would really appreciate a detailed answer. Thanks a lot if you can help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 15 Nov 2020 14:44:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Select-variables-with-only-numerical-data-select-numbers-with/m-p/698962#M9485</guid>
      <dc:creator>C_L</dc:creator>
      <dc:date>2020-11-15T14:44:44Z</dc:date>
    </item>
    <item>
      <title>Re: Select variables with only numerical data select numbers with certain number of digits</title>
      <link>https://communities.sas.com/t5/SAS-Studio/Select-variables-with-only-numerical-data-select-numbers-with/m-p/698967#M9486</link>
      <description>&lt;P&gt;I take it that you want to select&amp;nbsp;&lt;EM&gt;observations(rows)&lt;/EM&gt; where the EAN&amp;nbsp;&lt;EM&gt;column(variable)&lt;/EM&gt; contains only digits.&lt;/P&gt;
&lt;P&gt;Selecting&amp;nbsp;&lt;EM&gt;variables&lt;/EM&gt; is done with KEEP or DROP statements, or KEEP= or DROP= dataset options, and I am quite confident that is not what you have in mind.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can search for characters that are not digits with the&amp;nbsp;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.4&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p1m0n4833qyto5n1e793r44uuozv.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;NOTDIGIT&lt;/A&gt;&amp;nbsp;function. Use STRIP to remove trailing and leading blanks, as these are also considered non-digits.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the first step will look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data
  valid
  invalid
;
set have;
if notdigit(strip(ean)) /* a value of 0 (false) means no non-digits were found */
then output invalid;
else output valid;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 15 Nov 2020 15:41:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/Select-variables-with-only-numerical-data-select-numbers-with/m-p/698967#M9486</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-15T15:41:09Z</dc:date>
    </item>
  </channel>
</rss>

