<?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 How to extract desired numericals in irregular cells? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-extract-desired-numericals-in-irregular-cells/m-p/197809#M49434</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have an excel data file. In that file there are two columns I need to use and one column of it is irregular. As you guess I need to extract some numerical variables from that irregular contained column. For example I need to find the zipcodes which starts with "60". I have managed to write the formula of it in excel which is&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;"=IFERROR(IF(AND(LEN(TRIM(SUBSTITUTE(MID(K2,FIND(TEXT($L$1,0),K2,1)-1,1)&amp;amp;MID(K2,FIND(TEXT($L$1,0),K2,1)+5,1),CHAR(160),"")))=0,MID(K2,FIND(TEXT($L$1,0),K2,1),2)&amp;lt;&amp;gt;RIGHT(K2,2)),$L$1,"X"),"X")"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Zip codes are 5 digits.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What does this formula do? : It finds the starting position of desired 2 digit then&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1- Check if the letter before that 2 zip codes is empty and &lt;BR /&gt;2- Check if the 3 letter after that 2 zip code is empty and&lt;BR /&gt;3- Check if there is any letter after 2 zip code just in case those digits are the last letter of that cell.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can see some lines of the source excel file. If you are not able to download it I added some lines as well.&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 569px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD height="20" width="483"&gt;Irregular Column&lt;/TD&gt;&lt;TD width="86"&gt;Desired zip codes Starting with&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;a-haUKxUt 60000 WawawxwK tIhwahwTw 60&lt;/TD&gt;&lt;TD align="right"&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;KxIwaww 66000 yawtIh yInbaTwTw 66-60&lt;/TD&gt;&lt;TD align="right"&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;wtwwwxhh 00666 WaIwxw twIawahwwTw 6&lt;/TD&gt;&lt;TD align="right"&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;wUwt Vth 060006 00000 *** ***&lt;/TD&gt;&lt;TD align="right"&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;awaKx 06060 IhtttwTxwT tawtttIhtaw wTw&lt;BR /&gt;&amp;nbsp; 666&lt;/TD&gt;&lt;TD align="right"&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;KxIwaww 60066 yawtIh YtwnbKwTw 00&lt;/TD&gt;&lt;TD align="right"&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;wUwt Vth 660666 00000 *** ***&lt;/TD&gt;&lt;TD align="right"&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;wUwt Vth 600660 00000 *** ***&lt;/TD&gt;&lt;TD align="right"&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;awaKx twUyta 00666 yxw atwTaw yxtawwTw 60&lt;/TD&gt;&lt;TD align="right"&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;awaKx twtwwaw 06600 xUtwyUwt ytyIhtaw wTw&lt;BR /&gt;&amp;nbsp; 66&lt;/TD&gt;&lt;TD align="right"&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;TatUT-hxy+tUT 00006 wUaytyxUwah/TyUawIh&lt;BR /&gt;&amp;nbsp; txhtahwxtnbxaw tx&lt;/TD&gt;&lt;TD align="right"&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;Iwwx-wxwKT 66660 ttwahyUwt yttyawtatwaw&lt;BR /&gt;&amp;nbsp; wTw 600&lt;/TD&gt;&lt;TD align="right"&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help or idea is appreciated. Thanks in advance, have a nice day.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 02 Jun 2015 11:53:21 GMT</pubDate>
    <dc:creator>agodba</dc:creator>
    <dc:date>2015-06-02T11:53:21Z</dc:date>
    <item>
      <title>How to extract desired numericals in irregular cells?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-extract-desired-numericals-in-irregular-cells/m-p/197809#M49434</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have an excel data file. In that file there are two columns I need to use and one column of it is irregular. As you guess I need to extract some numerical variables from that irregular contained column. For example I need to find the zipcodes which starts with "60". I have managed to write the formula of it in excel which is&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;"=IFERROR(IF(AND(LEN(TRIM(SUBSTITUTE(MID(K2,FIND(TEXT($L$1,0),K2,1)-1,1)&amp;amp;MID(K2,FIND(TEXT($L$1,0),K2,1)+5,1),CHAR(160),"")))=0,MID(K2,FIND(TEXT($L$1,0),K2,1),2)&amp;lt;&amp;gt;RIGHT(K2,2)),$L$1,"X"),"X")"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Zip codes are 5 digits.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What does this formula do? : It finds the starting position of desired 2 digit then&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1- Check if the letter before that 2 zip codes is empty and &lt;BR /&gt;2- Check if the 3 letter after that 2 zip code is empty and&lt;BR /&gt;3- Check if there is any letter after 2 zip code just in case those digits are the last letter of that cell.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can see some lines of the source excel file. If you are not able to download it I added some lines as well.&lt;/P&gt;&lt;TABLE border="0" cellpadding="0" cellspacing="0" style="width: 569px;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD height="20" width="483"&gt;Irregular Column&lt;/TD&gt;&lt;TD width="86"&gt;Desired zip codes Starting with&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;a-haUKxUt 60000 WawawxwK tIhwahwTw 60&lt;/TD&gt;&lt;TD align="right"&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;KxIwaww 66000 yawtIh yInbaTwTw 66-60&lt;/TD&gt;&lt;TD align="right"&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;wtwwwxhh 00666 WaIwxw twIawahwwTw 6&lt;/TD&gt;&lt;TD align="right"&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;wUwt Vth 060006 00000 *** ***&lt;/TD&gt;&lt;TD align="right"&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;awaKx 06060 IhtttwTxwT tawtttIhtaw wTw&lt;BR /&gt;&amp;nbsp; 666&lt;/TD&gt;&lt;TD align="right"&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;KxIwaww 60066 yawtIh YtwnbKwTw 00&lt;/TD&gt;&lt;TD align="right"&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;wUwt Vth 660666 00000 *** ***&lt;/TD&gt;&lt;TD align="right"&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;wUwt Vth 600660 00000 *** ***&lt;/TD&gt;&lt;TD align="right"&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;awaKx twUyta 00666 yxw atwTaw yxtawwTw 60&lt;/TD&gt;&lt;TD align="right"&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;awaKx twtwwaw 06600 xUtwyUwt ytyIhtaw wTw&lt;BR /&gt;&amp;nbsp; 66&lt;/TD&gt;&lt;TD align="right"&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;TatUT-hxy+tUT 00006 wUaytyxUwah/TyUawIh&lt;BR /&gt;&amp;nbsp; txhtahwxtnbxaw tx&lt;/TD&gt;&lt;TD align="right"&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;Iwwx-wxwKT 66660 ttwahyUwt yttyawtatwaw&lt;BR /&gt;&amp;nbsp; wTw 600&lt;/TD&gt;&lt;TD align="right"&gt;60&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help or idea is appreciated. Thanks in advance, have a nice day.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Jun 2015 11:53:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-extract-desired-numericals-in-irregular-cells/m-p/197809#M49434</guid>
      <dc:creator>agodba</dc:creator>
      <dc:date>2015-06-02T11:53:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract desired numericals in irregular cells?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-extract-desired-numericals-in-irregular-cells/m-p/197810#M49435</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You seem to be asking for advice on Excel issues, maybe post it on an Excel forum?&amp;nbsp; To do this in SAS then you could use several functions, or perl regular expressions.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Jun 2015 12:04:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-extract-desired-numericals-in-irregular-cells/m-p/197810#M49435</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2015-06-02T12:04:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract desired numericals in irregular cells?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-extract-desired-numericals-in-irregular-cells/m-p/197811#M49436</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Sorry if I caused any missunderstanding. I don't ask for excel advices. I need to use that excel source file in SAS as it is. &lt;/P&gt;&lt;P&gt;I have written the excel solution that i used in order to give some ideas about my questions, also I thought that some SAS codes that i don't know yet can be written by understanding the rules that i used in excel formulas.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;So all i want to learn is those several functions, or perl regular expressions that you mentioned.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Jun 2015 13:02:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-extract-desired-numericals-in-irregular-cells/m-p/197811#M49436</guid>
      <dc:creator>agodba</dc:creator>
      <dc:date>2015-06-02T13:02:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract desired numericals in irregular cells?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-extract-desired-numericals-in-irregular-cells/m-p/197812#M49437</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use the scan() function to extract the "words" from the long string (do it iteratively from 1 to countw()).&lt;/P&gt;&lt;P&gt;Then check each "word" for a length of 5 and that it is numeric (use the notdigit() function).&lt;/P&gt;&lt;P&gt;Since you now know that you have 5 digits, you only need to compare the substr(string_var,1,2) to your reference value ('60').&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Jun 2015 13:20:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-extract-desired-numericals-in-irregular-cells/m-p/197812#M49437</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2015-06-02T13:20:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract desired numericals in irregular cells?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-extract-desired-numericals-in-irregular-cells/m-p/197813#M49438</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To add a bit of context to KurtBremser's answer:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; length nextword $ 6;&amp;nbsp; /* don't need to extract any more than 6 characters */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; length zip_code $ 5;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if irregular_string &amp;gt; ' ' then do i=1 to countw(irregular_string, ' ');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; nextword = scan(irregular_string, i, ' ');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if length(nextword)=5 and notdigit(next_word) = 6 then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if next_word =: '60' then zip_code = next_word;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; drop next_word i;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The logic might be a bit trickier than it looks.&amp;nbsp; Once the length of a word is established as 5, the 6th character must be a blank.&amp;nbsp; So the NOTDIGIT function must return 6 (since blanks are not digits) to identify a 5-digit number.&amp;nbsp; Also, by defining the length of zip_code as $ 5, that trailing blank is automatically dropped from its value.&amp;nbsp; Also note that COUNTW uses a set of characters as default delimiters, so specify a blank as the only allowable delimiter.&amp;nbsp; Using =: is a faster way to examine the beginning of a character string (instead of substr).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Jun 2015 17:15:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-extract-desired-numericals-in-irregular-cells/m-p/197813#M49438</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-06-02T17:15:07Z</dc:date>
    </item>
  </channel>
</rss>

