<?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: Find String of numbers in a text field in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-String-of-numbers-in-a-text-field/m-p/685820#M208038</link>
    <description>&lt;P&gt;There are several methods to extract the number, as shown in next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set have;
      len =18;  
/*1*/   var1 = substr(string, index(string,'368),len);

/*2*/ var2 = compress(string,,'kd');

/*3*/ var3 = substr(string,(find(string,'368'),len);

put var1= var2= var3=;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 22 Sep 2020 18:38:46 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2020-09-22T18:38:46Z</dc:date>
    <item>
      <title>Find String of numbers in a text field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-String-of-numbers-in-a-text-field/m-p/685768#M208031</link>
      <description>&lt;P&gt;Enterprise Guide 7.12&lt;/P&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I am trying to find a number in a text field and extract it to it's own column. I have a column that contains text and anywhere in that field I may have a number like 368295194613104679. The number is always 18 characters long and currently starts with 368.&lt;/P&gt;&lt;P&gt;I can find all the records that have that number by using LIKE '368%' now I need to extract it so it does show for example 368295194613104679, in a new column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am coding this with Proc SQL.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas would be greatly appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2020 17:18:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-String-of-numbers-in-a-text-field/m-p/685768#M208031</guid>
      <dc:creator>R_Auger</dc:creator>
      <dc:date>2020-09-22T17:18:00Z</dc:date>
    </item>
    <item>
      <title>Re: Find String of numbers in a text field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-String-of-numbers-in-a-text-field/m-p/685769#M208032</link>
      <description>&lt;P&gt;You want to use the ANYDIGIT() function, which finds the location in the string of the first digit that it finds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then, you can extract the string via&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;substr(string,anydigit(string),18) as numbers&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Sep 2020 17:19:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-String-of-numbers-in-a-text-field/m-p/685769#M208032</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-09-22T17:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: Find String of numbers in a text field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-String-of-numbers-in-a-text-field/m-p/685802#M208036</link>
      <description>&lt;P&gt;Thanks, I'll try that solution. I was able to get this to work&amp;nbsp;&lt;BR /&gt;SUBSTR(t2.NOTES,FIND(t2.NOTES,"368"),18)&lt;/P&gt;</description>
      <pubDate>Tue, 22 Sep 2020 18:06:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-String-of-numbers-in-a-text-field/m-p/685802#M208036</guid>
      <dc:creator>R_Auger</dc:creator>
      <dc:date>2020-09-22T18:06:00Z</dc:date>
    </item>
    <item>
      <title>Re: Find String of numbers in a text field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-String-of-numbers-in-a-text-field/m-p/685820#M208038</link>
      <description>&lt;P&gt;There are several methods to extract the number, as shown in next code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set have;
      len =18;  
/*1*/   var1 = substr(string, index(string,'368),len);

/*2*/ var2 = compress(string,,'kd');

/*3*/ var3 = substr(string,(find(string,'368'),len);

put var1= var2= var3=;

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Sep 2020 18:38:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-String-of-numbers-in-a-text-field/m-p/685820#M208038</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-09-22T18:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: Find String of numbers in a text field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-String-of-numbers-in-a-text-field/m-p/685965#M208088</link>
      <description>&lt;P&gt;This is a case where PRX (Pearl regular expressions) look right:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  text='dafgjakgkgakga368123456789012345fagagagaga';
run;

data want;
  set have;
  length number $18;
  pos=prxmatch('/368\d{15}/',text);
  if pos;
  number=substr(text,pos,18);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to do it in SQL, I would suggest something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
  create table want as select text,substr(text,pos,18) as number length=18
  from(select text,prxmatch('/368\d{15}/',text) as pos from have)&lt;BR /&gt;  where pos&amp;gt;0;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The advantage to using PRX is that you can make sure that you actually have 18 digits ("368\d{15}" means "368" plus 15 digits. You say that the number currently starts with "368", if what you really want is any 18 digits, just change the PRXMATCH first parameter to "/\d{18}/".&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 07:06:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-String-of-numbers-in-a-text-field/m-p/685965#M208088</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-09-23T07:06:44Z</dc:date>
    </item>
  </channel>
</rss>

