<?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: Extract numeric caracters and alphanumeric one from strings without delimiter in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extract-numeric-caracters-and-alphanumeric-one-from-strings/m-p/616419#M180453</link>
    <description>&lt;P&gt;Using regular expressions seems to be a good idea, if the name of a client always starts with da letter and ends with a letter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data file_names;
   length 
      filename $ 50
      datetime $ 12
      client $ 20
      lastNumber $ 10 
   ;

   input filename;

   _rx = prxparse('/(\d{6})(\D+)(\d+)/');

   if prxmatch(_rx, filename) then do;
      datetime = prxposn(_rx, 1, filename);
      client = prxposn(_rx, 2, filename);
      lastNumber = prxposn(_rx, 3, filename);     
   end;

   datalines;
201905061636Pepsi65562.xls
201907041351Cisco12345Test.xls
201911050612Lenovo55003modv4.xls
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 10 Jan 2020 11:09:43 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2020-01-10T11:09:43Z</dc:date>
    <item>
      <title>Extract numeric caracters and alphanumeric one from strings without delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-numeric-caracters-and-alphanumeric-one-from-strings/m-p/616401#M180447</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need filter my datas from name of files which are copied in the system.&lt;/P&gt;&lt;P&gt;These files are sometimes renamed and somtimes not.&lt;/P&gt;&lt;P&gt;These files are named like that "201905061636XXXXXXXX65562.xls" but the length of the name is not always the same.&lt;/P&gt;&lt;P&gt;In the beginning of the name, there is the date and the hour when the file was loaded so the length is always the same.&lt;/P&gt;&lt;P&gt;XXXXX is the name of the client and the length changes.&lt;/P&gt;&lt;P&gt;Then there are numbers at the end of the file and, sometimes, when the file have been manually modified, there letter like "Modify" or "test" or "testV2", "modifyV2" etc... after this last numeric string...&lt;/P&gt;&lt;P&gt;I would like to cut these strings to identify the date and time in a single variable then the name of the client and the the last number writen in the name file. I dont want words like "Modify" or "Test" at the end.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't find how to do that. I guess I can use Scan function or something like that but I have no idea how to use a sas function with that kind of variable. Of course I get the date and time with:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;date=substr(name,1,12)&amp;nbsp; as the length is always the same but I don't know what to do with the other parts I need.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2020 10:06:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-numeric-caracters-and-alphanumeric-one-from-strings/m-p/616401#M180447</guid>
      <dc:creator>vince_est</dc:creator>
      <dc:date>2020-01-10T10:06:07Z</dc:date>
    </item>
    <item>
      <title>Re: Extract numeric caracters and alphanumeric one from strings without delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-numeric-caracters-and-alphanumeric-one-from-strings/m-p/616419#M180453</link>
      <description>&lt;P&gt;Using regular expressions seems to be a good idea, if the name of a client always starts with da letter and ends with a letter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data file_names;
   length 
      filename $ 50
      datetime $ 12
      client $ 20
      lastNumber $ 10 
   ;

   input filename;

   _rx = prxparse('/(\d{6})(\D+)(\d+)/');

   if prxmatch(_rx, filename) then do;
      datetime = prxposn(_rx, 1, filename);
      client = prxposn(_rx, 2, filename);
      lastNumber = prxposn(_rx, 3, filename);     
   end;

   datalines;
201905061636Pepsi65562.xls
201907041351Cisco12345Test.xls
201911050612Lenovo55003modv4.xls
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2020 11:09:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-numeric-caracters-and-alphanumeric-one-from-strings/m-p/616419#M180453</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-01-10T11:09:43Z</dc:date>
    </item>
    <item>
      <title>Re: Extract numeric caracters and alphanumeric one from strings without delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-numeric-caracters-and-alphanumeric-one-from-strings/m-p/616420#M180454</link>
      <description>&lt;P&gt;You can use the SUBSTR() function to extract the date/time, since you say this will always be the same length. To extract the name, you can use the ANYDIGIT() function to see where the next number begins and then SUBSTR() to extract the name. Then you could use ANYALPHA() to find where the next letter is and then SUBSTR() again to extract the number.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2020 11:19:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-numeric-caracters-and-alphanumeric-one-from-strings/m-p/616420#M180454</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-01-10T11:19:43Z</dc:date>
    </item>
    <item>
      <title>Re: Extract numeric caracters and alphanumeric one from strings without delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-numeric-caracters-and-alphanumeric-one-from-strings/m-p/616425#M180456</link>
      <description>&lt;P&gt;Thank you so much for your answers. I'll try them.&lt;/P&gt;&lt;P&gt;I continued to search over internet after I posted my message and I've found a piece of code I adapted to my need:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* words to match delimited by "|" */&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; words = MODIFIE|MODIFIEV2|MODIFV2|MODIF|V2|test|new|rectifie|MODIFIE_KOMP|MODIFIE_KOMPV2|MODIFIE_KOMPv2|modifie|MODIF2|sansmauvaisedate|MODIFIEtestianpourjcc|v3|GA|GE|MODIFIEE;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; example_clean;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; testtri2;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; _n_ = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;do&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;retain&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; regex;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;drop&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; regex;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;regex = prxparse(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"s/(&amp;amp;words)\s+//"&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;string = prxchange(regex, &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;, want2); &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to manually enter the words I want to delete at the end of the filename but I works.&lt;/P&gt;&lt;P&gt;I 'll try your solutions after lunch and I'll tell you the results&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2020 11:35:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-numeric-caracters-and-alphanumeric-one-from-strings/m-p/616425#M180456</guid>
      <dc:creator>vince_est</dc:creator>
      <dc:date>2020-01-10T11:35:21Z</dc:date>
    </item>
    <item>
      <title>Re: Extract numeric caracters and alphanumeric one from strings without delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-numeric-caracters-and-alphanumeric-one-from-strings/m-p/616426#M180457</link>
      <description>&lt;P&gt;I couldn't wait so I tried Andreas_ids solution and it works very well!&lt;/P&gt;&lt;P&gt;I have to lear how to use regular expressions, it seems very powerful.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much for your help!&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2020 11:45:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-numeric-caracters-and-alphanumeric-one-from-strings/m-p/616426#M180457</guid>
      <dc:creator>vince_est</dc:creator>
      <dc:date>2020-01-10T11:45:26Z</dc:date>
    </item>
    <item>
      <title>Re: Extract numeric caracters and alphanumeric one from strings without delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-numeric-caracters-and-alphanumeric-one-from-strings/m-p/616429#M180458</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   input filename $80.;
      datetime = scan(filename,1,,'kd');
      client = scan(filename,1,,'d');
      lastNumber = scan(filename,2,,'kd');    
   datalines;
201905061636Pepsi65562.xls
201907041351Cisco12345Test.xls
201911050612Lenovo55003modv4.xls
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 10 Jan 2020 12:01:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-numeric-caracters-and-alphanumeric-one-from-strings/m-p/616429#M180458</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-01-10T12:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: Extract numeric caracters and alphanumeric one from strings without delimiter</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-numeric-caracters-and-alphanumeric-one-from-strings/m-p/616436#M180462</link>
      <description>&lt;P&gt;That's thought process makes you stand out and SHARPPPPPPPPPPPPPPPPPPPPPP!!!!&lt;/P&gt;</description>
      <pubDate>Fri, 10 Jan 2020 12:38:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-numeric-caracters-and-alphanumeric-one-from-strings/m-p/616436#M180462</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-10T12:38:54Z</dc:date>
    </item>
  </channel>
</rss>

