<?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: How to split numeric and alpha into different variables with mathematical characters invollved in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-numeric-and-alpha-into-different-variables-with/m-p/843816#M333587</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/250786"&gt;@FriendJen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello! I have a result variable that is a string and I'm splitting it into two variables, one for numeric data and one for character data. For example, if my original variable is RESULT, I want to split it into NUM and CHAR. Right now I'm using something like&lt;/P&gt;
&lt;PRE&gt;if ANYALPHA(RESULT)&amp;gt;0 then CHAR=RESULT; ELSE NUM=INPUT(RESULT, BEST.);&lt;/PRE&gt;
&lt;P&gt;The problem happens when my RESULT variable has a non-alphanumeric character because then I can't use INPUT to change the string to numeric.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;RESULT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;NUM&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CHAR&lt;/P&gt;
&lt;P&gt;'Negative'&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'Negative'&lt;/P&gt;
&lt;P&gt;'124.3'&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;124.3&lt;/P&gt;
&lt;P&gt;'&amp;lt;50'&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;50&lt;/P&gt;
&lt;P&gt;'Other'&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'Other'&lt;/P&gt;
&lt;P&gt;'&amp;lt;99.9'&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;99.9&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know I can use COMPRESS(RESULT, '&amp;lt;'), but is there another way that doesn't rely on me knowing the specific character? The dataset I'm using is huge, so there could be variety I don't know about.&lt;BR /&gt;&lt;BR /&gt;Is there a generalized "remove non-math" type of function I can use so I can keep decimals and negatives but remove other symbols?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I would say no.&amp;nbsp; But the list of valid characters for strings that look like numerical expressions is pretty limited.&lt;/P&gt;
&lt;P&gt;Basic operators&lt;/P&gt;
&lt;PRE&gt;+ - / *&lt;/PRE&gt;
&lt;P&gt;Comparison operators&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;lt; = &amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Punctuation&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;. , $ %&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  input result $80. ;
cards;
Negative
124.3
&amp;lt;50
Other
&amp;lt;99.9
50%
;


data want;
  set have;
  if verify(result,'0123456789.,+-/* &amp;lt;=&amp;gt;$%') then char=result;
  else do;
     num_string=result;
     num=input(compress(num_string,'&amp;lt;=&amp;gt;'),??comma32.);
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;                                num_
Obs    result      char        string     num

 1     Negative    Negative                 .
 2     124.3                   124.3     124.3
 3     &amp;lt;50                     &amp;lt;50        50.0
 4     Other       Other                    .
 5     &amp;lt;99.9                   &amp;lt;99.9      99.9
 6     50%                     50%        50.0
&lt;/PRE&gt;</description>
    <pubDate>Fri, 11 Nov 2022 16:25:44 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-11-11T16:25:44Z</dc:date>
    <item>
      <title>How to split numeric and alpha into different variables with mathematical characters invollved</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-numeric-and-alpha-into-different-variables-with/m-p/843810#M333585</link>
      <description>&lt;P&gt;Hello! I have a result variable that is a string and I'm splitting it into two variables, one for numeric data and one for character data. For example, if my original variable is RESULT, I want to split it into NUM and CHAR. Right now I'm using something like&lt;/P&gt;&lt;PRE&gt;if ANYALPHA(RESULT)&amp;gt;0 then CHAR=RESULT; ELSE NUM=INPUT(RESULT, BEST.);&lt;/PRE&gt;&lt;P&gt;The problem happens when my RESULT variable has a non-alphanumeric character because then I can't use INPUT to change the string to numeric.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;RESULT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;NUM&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CHAR&lt;/P&gt;&lt;P&gt;'Negative'&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'Negative'&lt;/P&gt;&lt;P&gt;'124.3'&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;124.3&lt;/P&gt;&lt;P&gt;'&amp;lt;50'&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;50&lt;/P&gt;&lt;P&gt;'Other'&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'Other'&lt;/P&gt;&lt;P&gt;'&amp;lt;99.9'&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;99.9&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know I can use COMPRESS(RESULT, '&amp;lt;'), but is there another way that doesn't rely on me knowing the specific character? The dataset I'm using is huge, so there could be variety I don't know about.&lt;BR /&gt;&lt;BR /&gt;Is there a generalized "remove non-math" type of function I can use so I can keep decimals and negatives but remove other symbols?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Nov 2022 15:24:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-numeric-and-alpha-into-different-variables-with/m-p/843810#M333585</guid>
      <dc:creator>FriendJen</dc:creator>
      <dc:date>2022-11-11T15:24:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to split numeric and alpha into different variables with mathematical characters invollved</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-numeric-and-alpha-into-different-variables-with/m-p/843816#M333587</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/250786"&gt;@FriendJen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello! I have a result variable that is a string and I'm splitting it into two variables, one for numeric data and one for character data. For example, if my original variable is RESULT, I want to split it into NUM and CHAR. Right now I'm using something like&lt;/P&gt;
&lt;PRE&gt;if ANYALPHA(RESULT)&amp;gt;0 then CHAR=RESULT; ELSE NUM=INPUT(RESULT, BEST.);&lt;/PRE&gt;
&lt;P&gt;The problem happens when my RESULT variable has a non-alphanumeric character because then I can't use INPUT to change the string to numeric.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;RESULT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;NUM&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CHAR&lt;/P&gt;
&lt;P&gt;'Negative'&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'Negative'&lt;/P&gt;
&lt;P&gt;'124.3'&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;124.3&lt;/P&gt;
&lt;P&gt;'&amp;lt;50'&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;50&lt;/P&gt;
&lt;P&gt;'Other'&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'Other'&lt;/P&gt;
&lt;P&gt;'&amp;lt;99.9'&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;99.9&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know I can use COMPRESS(RESULT, '&amp;lt;'), but is there another way that doesn't rely on me knowing the specific character? The dataset I'm using is huge, so there could be variety I don't know about.&lt;BR /&gt;&lt;BR /&gt;Is there a generalized "remove non-math" type of function I can use so I can keep decimals and negatives but remove other symbols?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I would say no.&amp;nbsp; But the list of valid characters for strings that look like numerical expressions is pretty limited.&lt;/P&gt;
&lt;P&gt;Basic operators&lt;/P&gt;
&lt;PRE&gt;+ - / *&lt;/PRE&gt;
&lt;P&gt;Comparison operators&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;lt; = &amp;gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Punctuation&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;. , $ %&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
  input result $80. ;
cards;
Negative
124.3
&amp;lt;50
Other
&amp;lt;99.9
50%
;


data want;
  set have;
  if verify(result,'0123456789.,+-/* &amp;lt;=&amp;gt;$%') then char=result;
  else do;
     num_string=result;
     num=input(compress(num_string,'&amp;lt;=&amp;gt;'),??comma32.);
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;                                num_
Obs    result      char        string     num

 1     Negative    Negative                 .
 2     124.3                   124.3     124.3
 3     &amp;lt;50                     &amp;lt;50        50.0
 4     Other       Other                    .
 5     &amp;lt;99.9                   &amp;lt;99.9      99.9
 6     50%                     50%        50.0
&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Nov 2022 16:25:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-numeric-and-alpha-into-different-variables-with/m-p/843816#M333587</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-11T16:25:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to split numeric and alpha into different variables with mathematical characters invollved</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-split-numeric-and-alpha-into-different-variables-with/m-p/843832#M333596</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/250786"&gt;@FriendJen&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello! I have a result variable that is a string and I'm splitting it into two variables, one for numeric data and one for character data. For example, if my original variable is RESULT, I want to split it into NUM and CHAR. Right now I'm using something like&lt;/P&gt;
&lt;PRE&gt;if ANYALPHA(RESULT)&amp;gt;0 then CHAR=RESULT; ELSE NUM=INPUT(RESULT, BEST.);&lt;/PRE&gt;
&lt;P&gt;The problem happens when my RESULT variable has a non-alphanumeric character because then I can't use INPUT to change the string to numeric.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;RESULT&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;NUM&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CHAR&lt;/P&gt;
&lt;P&gt;'Negative'&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'Negative'&lt;/P&gt;
&lt;P&gt;'124.3'&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;124.3&lt;/P&gt;
&lt;P&gt;'&amp;lt;50'&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;lt;50&lt;/P&gt;
&lt;P&gt;'Other'&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'Other'&lt;/P&gt;
&lt;P&gt;'&amp;lt;99.9'&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;99.9&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know I can use COMPRESS(RESULT, '&amp;lt;'), but is there another way that doesn't rely on me knowing the specific character? The dataset I'm using is huge, so there could be variety I don't know about.&lt;BR /&gt;&lt;BR /&gt;Is there a generalized "remove non-math" type of function I can use so I can keep decimals and negatives but remove other symbols?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Question about possible content: Do you have any values that might be expressed in scientific notation such as 1.34E6 instead of&amp;nbsp; 1340000? (or even larger values or small values like 1.34E-15? )&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Verify code&lt;/P&gt;</description>
      <pubDate>Fri, 11 Nov 2022 17:40:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-split-numeric-and-alpha-into-different-variables-with/m-p/843832#M333596</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-11-11T17:40:56Z</dc:date>
    </item>
  </channel>
</rss>

