<?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 Extract the value from character string in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Extract-the-value-from-character-string/m-p/522822#M4518</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to extract the value from the charater string and save it in numeric format. Would you please kindly help me how to make it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Txn_Desc&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CAP:P-3%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CAP:P-2.75%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CAP:P-3.1%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;LC:CAP:P-3.25%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;HIB+1%;LC;CAP: P-4.15%&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;e.g. I want to extract the value 3.25 from the string : LC:CAP:P-3.25%&lt;/P&gt;&lt;P&gt;The extract logic should like this&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Extracting the value which after the "P-" and before the "%" Sign.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
    <pubDate>Thu, 20 Dec 2018 09:53:15 GMT</pubDate>
    <dc:creator>New_SAS_user76</dc:creator>
    <dc:date>2018-12-20T09:53:15Z</dc:date>
    <item>
      <title>Extract the value from character string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-the-value-from-character-string/m-p/522822#M4518</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to extract the value from the charater string and save it in numeric format. Would you please kindly help me how to make it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;STRONG&gt;Txn_Desc&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CAP:P-3%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CAP:P-2.75%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;CAP:P-3.1%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;LC:CAP:P-3.25%&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;HIB+1%;LC;CAP: P-4.15%&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;e.g. I want to extract the value 3.25 from the string : LC:CAP:P-3.25%&lt;/P&gt;&lt;P&gt;The extract logic should like this&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Extracting the value which after the "P-" and before the "%" Sign.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Thu, 20 Dec 2018 09:53:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-the-value-from-character-string/m-p/522822#M4518</guid>
      <dc:creator>New_SAS_user76</dc:creator>
      <dc:date>2018-12-20T09:53:15Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the value from character string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-the-value-from-character-string/m-p/522823#M4519</link>
      <description>&lt;P&gt;Ideally, post example data as data steps with datalines in a code window ("little running man" or {i} button).&lt;/P&gt;
&lt;P&gt;The main posting windows has the habit of "beautifying" text, as can be seen by the smileys in your post.&lt;/P&gt;
&lt;P&gt;Guessing what you have, I suggest this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines truncover;
input txn_desc $30.;
datalines4;
CAP:P-3%
CAP:P-2.75%
CAP:P-3.1%
LC:CAP:P-3.25%
HIB+1%;LC;CAP: P-4.15%
;;;;
run;

data want;
set have;
index = index(txn_desc,'P-');
_txn = substr(txn_desc,index+2);
value = input(scan(_txn,1,'%'),best.);
drop index _txn;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;txn_desc                  value

CAP:P-3%                   3.00
CAP:P-2.75%                2.75
CAP:P-3.1%                 3.10
LC:CAP:P-3.25%             3.25
HIB+1%;LC;CAP: P-4.15%     4.15
&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Dec 2018 10:13:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-the-value-from-character-string/m-p/522823#M4519</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-12-20T10:13:38Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the value from character string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-the-value-from-character-string/m-p/522824#M4520</link>
      <description>&lt;P&gt;Well, the simple answer here normally is:&lt;/P&gt;
&lt;PRE&gt;want=input(compress(have,".","kd"),best.);
&lt;/PRE&gt;
&lt;P&gt;However you have multiple data items in one string - which is bad data modelling and hence you have to process further.&lt;/P&gt;
&lt;P&gt;First you will need to split the string up into elements, i.e. one data cell for one data item, e.g.:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  length wrd $200;
  do i=1 to countw(txn_desc,";");
    wrd=scan(txn_desc,i,";");
    output;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;Now you can then apply the compress to the new variable:&lt;/P&gt;
&lt;PRE&gt;data want;
  set want;
  new_var=input(compress(wrd,".","kd"),best.);
run;&lt;/PRE&gt;
&lt;P&gt;Note, not tested - post test data in the form of a datastep in future!!!&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course if it is really only that one data element, then you might be able to get away with:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  if index(txn_desc,"P-");
  want=input(substr(txn_desc,index(txn,"P-")+2,lengthn(txn_desc)-1),best.);
run;&lt;/PRE&gt;
&lt;P&gt;Again untested.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Dec 2018 10:17:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-the-value-from-character-string/m-p/522824#M4520</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-12-20T10:17:21Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the value from character string</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Extract-the-value-from-character-string/m-p/522827#M4521</link>
      <description>&lt;P&gt;with perl regular expression&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
value=input(prxchange('s/(.*p-)(.*)(%)/$2/i',-1,strip(txn_desc)),best.);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Dec 2018 10:57:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Extract-the-value-from-character-string/m-p/522827#M4521</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2018-12-20T10:57:58Z</dc:date>
    </item>
  </channel>
</rss>

