<?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 separate character from numeric ? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-separate-character-from-numeric/m-p/567130#M159449</link>
    <description>&lt;P&gt;Try this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	txt = "100/50 mg medicin";
	c = compress(txt,"0123456789.,/ ","K"); *K is to keep the chars you specified.;
	txt_b = compress(txt,"0123456789.,/");
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 19 Jun 2019 04:11:12 GMT</pubDate>
    <dc:creator>heffo</dc:creator>
    <dc:date>2019-06-19T04:11:12Z</dc:date>
    <item>
      <title>How to separate character from numeric ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-separate-character-from-numeric/m-p/567129#M159448</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i want to separate character from numeric&amp;nbsp; value&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for eg :&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Txt&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;50mg&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;slicing data&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;100/50 mg&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;mg&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;unknown&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0.25 mmmgb&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how to get the output like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;c&lt;/TD&gt;&lt;TD&gt;Txt_b&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;mg&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;slicing data&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;100/50&lt;/TD&gt;&lt;TD&gt;mg&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;mg&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;unknown&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;0.25&lt;/TD&gt;&lt;TD&gt;mmmgb&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Wed, 19 Jun 2019 04:04:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-separate-character-from-numeric/m-p/567129#M159448</guid>
      <dc:creator>Aayushi_17</dc:creator>
      <dc:date>2019-06-19T04:04:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to separate character from numeric ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-separate-character-from-numeric/m-p/567130#M159449</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	txt = "100/50 mg medicin";
	c = compress(txt,"0123456789.,/ ","K"); *K is to keep the chars you specified.;
	txt_b = compress(txt,"0123456789.,/");
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Jun 2019 04:11:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-separate-character-from-numeric/m-p/567130#M159449</guid>
      <dc:creator>heffo</dc:creator>
      <dc:date>2019-06-19T04:11:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to separate character from numeric ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-separate-character-from-numeric/m-p/567131#M159450</link>
      <description>&lt;P&gt;100/50 isn't a valid numeric because of the "/". You could split it into two numerics - 100 and 50. How do you want to handle this?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 04:13:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-separate-character-from-numeric/m-p/567131#M159450</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2019-06-19T04:13:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to separate character from numeric ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-separate-character-from-numeric/m-p/567285#M159510</link>
      <description>&lt;P&gt;Here's an alternative option:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Obviously not as simple as the accepted solution, but still works regardless.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WORK.WANT (DROP=Re Position Length Start Stop);
	SET WORK.HAVE;
	FORMAT C $10. Txt_B $15.;
	IF _N_=1 THEN RE= PRXPARSE("m/0|1|2|3|4|5|6|7|8|9/oi");
	RETAIN Re;
	Start=1;
	Stop=LENGTH(Txt);
		 IF PRXMATCH(Re,Txt) = 0 THEN DO;
			 C		= ' ';
			 Txt_B	= Txt;
		 END;
	ELSE IF PRXMATCH(Re,Txt) &amp;gt; 0 THEN DO;
		CALL PRXNEXT(Re, Start, Stop, Txt, Position, Length);
		DO WHILE (Position &amp;gt; 0);
			 C	   = STRIP(SUBSTR(Txt, 1, Start-1));
	         Txt_B = STRIP(SUBSTR(Txt, Start, Stop));
	         CALL PRXNEXT(Re, Start, Stop, Txt, Position, Length);
		END;
	END;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 19 Jun 2019 14:05:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-separate-character-from-numeric/m-p/567285#M159510</guid>
      <dc:creator>tsap</dc:creator>
      <dc:date>2019-06-19T14:05:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to separate character from numeric ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-separate-character-from-numeric/m-p/567288#M159512</link>
      <description>&lt;P&gt;The main benefit to this option, over the other solution, is that depending on any other values in the text field, some issues may arise.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;If there is a value of "15/100 mg/d", this is something completely made up just to show what could occur with the accepted solution logic.&lt;/P&gt;&lt;P&gt;As it stands that logic would produce C="15/100/" Txt_B=" mgd". So there would be an incorrect slash at the end of the value in the C field and it would be removed from the Txt_B field. Even if you removed the '/' from the Txt_B logic you would still have a bad value of "/mg/d" with the incorrect slash in the front now. If you will never have starting values like this, then you will be fine with the accepted solution.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 14:11:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-separate-character-from-numeric/m-p/567288#M159512</guid>
      <dc:creator>tsap</dc:creator>
      <dc:date>2019-06-19T14:11:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to separate character from numeric ?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-separate-character-from-numeric/m-p/567295#M159515</link>
      <description>&lt;P&gt;If the accepted solution works to achieve your expected results, one recommendation I would make is regarding the "txt_b" line of logic.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As it stands the logic used to populate the "txt_b" field excludes the characters pulled in the "C" field above it, except for the blank space. This in turn causes any spaces between the numeric value and the character value to remain. So when you have "100/50 mg medicine", the blank between '50' and 'mg' remains. So to clean this up without incorrectly removing the blank between the words 'mg' and 'medicine', we can use the STRIP FUNCTION.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WORK.Want;
	SET WORK.Have;
	c 	  = COMPRESS(Txt,"0123456789.,/ ","K"); *K is to keep the chars you specified.;
	txt_b = STRIP(COMPRESS(Txt,"0123456789.,/"));
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jun 2019 14:21:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-separate-character-from-numeric/m-p/567295#M159515</guid>
      <dc:creator>tsap</dc:creator>
      <dc:date>2019-06-19T14:21:44Z</dc:date>
    </item>
  </channel>
</rss>

