<?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 characters in a field/cell in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extract-characters-in-a-field-cell/m-p/131738#M10728</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;*Here is the code you need &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data output ;&lt;/P&gt;&lt;P&gt;length newvars1-newvars11 $ 200;&lt;/P&gt;&lt;P&gt;set input;&lt;/P&gt;&lt;P&gt;array newvars (11) $;&lt;/P&gt;&lt;P&gt;do i=1 to countw(data,'|','m');&lt;/P&gt;&lt;P&gt;newvars(i)=strip(scan(data,i,'|','m'));&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 20 Mar 2015 03:53:39 GMT</pubDate>
    <dc:creator>jgfitton</dc:creator>
    <dc:date>2015-03-20T03:53:39Z</dc:date>
    <item>
      <title>Extract characters in a field/cell</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extract-characters-in-a-field-cell/m-p/131731#M10721</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a cell in a dataset that is pipe delimited.&amp;nbsp; I need to extract the first 5 numbers and the last 5.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Cell data example:&amp;nbsp; 18995|Pend-PrSu|18000_ProdSupReg|I|00102||||&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To get the first 5, I used the formula:&amp;nbsp; substr(data, 1,5).&amp;nbsp; It returned 18995.&lt;/P&gt;&lt;P&gt;To get the last 5, I used the formula:&amp;nbsp; substr(data, -9,-4).&amp;nbsp; Unsuccessful.&amp;nbsp; I got blanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How can I get the last 5 numbers?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 May 2013 17:22:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extract-characters-in-a-field-cell/m-p/131731#M10721</guid>
      <dc:creator>jen123</dc:creator>
      <dc:date>2013-05-07T17:22:56Z</dc:date>
    </item>
    <item>
      <title>Re: Extract characters in a field/cell</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extract-characters-in-a-field-cell/m-p/131732#M10722</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think you want the last 5 variables before the ||||. If so, you do not want to start the 4th position from the right (because that will include the final |) but instead start at the 5th position, and go 5 positions left from there.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you truly want just the last X characters, then you can do something like "reverse(substr(left(reverse(YOURVAR)),5,5))"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Remember in substr, the first arguement is your start and the second if your Total length to read AFTER your start, not your position you want to end at.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Let me know if you need further help, as there are ways to make this significantly more dynamic.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Brandon&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 May 2013 17:39:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extract-characters-in-a-field-cell/m-p/131732#M10722</guid>
      <dc:creator>Anotherdream</dc:creator>
      <dc:date>2013-05-07T17:39:39Z</dc:date>
    </item>
    <item>
      <title>Re: Extract characters in a field/cell</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extract-characters-in-a-field-cell/m-p/131733#M10723</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi, similarly (in some way) to what &lt;EM&gt;Anotherdream&lt;/EM&gt; suggested, here is what I thought of:&lt;/P&gt;&lt;P&gt;data in;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; length string $50.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; string = " 18995|Pend-PrSu|18000_ProdSupReg|I|00102||||";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; *remove the letters and other funny characters;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; temp_string = prxchange("s/[a-zA-Z|-]//", -1, string);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; *get the first 5 digits;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; string_first_5 = substr(temp_string, 1, 6);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; *get the last 5 digits;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; string_last_5 = translate(reverse(substr(reverse(trim(temp_string)), 1, 6)), "", "_");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc print data = in;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 May 2013 17:42:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extract-characters-in-a-field-cell/m-p/131733#M10723</guid>
      <dc:creator>AncaTilea</dc:creator>
      <dc:date>2013-05-07T17:42:09Z</dc:date>
    </item>
    <item>
      <title>Re: Extract characters in a field/cell</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extract-characters-in-a-field-cell/m-p/131734#M10724</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is a fairly robust way to get what you want :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;data in;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;length string $100 word $50;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;input string;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;do i = 1 to countw(string, "|");&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; word = scan(string, i, "|");&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not anyalpha(word) and anydigit(word) then do;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if missing(firstNumber) then firstNumber = input(word, ?? best.);&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else lastNumber = input(word, ?? best.);&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;drop string i word;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt; 18995|Pend-PrSu|18000_ProdSupReg|I|00102||||&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 May 2013 18:15:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extract-characters-in-a-field-cell/m-p/131734#M10724</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2013-05-07T18:15:07Z</dc:date>
    </item>
    <item>
      <title>Re: Extract characters in a field/cell</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extract-characters-in-a-field-cell/m-p/131735#M10725</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Looks like your data is delimited. Why not just use SCAN function?&amp;nbsp; By default it will treat multiple delimiters as one so you would want to use:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data _null_;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; string='18995|Pend-PrSu|18000_ProdSupReg|I|00102||||&amp;nbsp; ';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; first = scan(string,1,'|');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; last = scan(trim(string),-1,'|');&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; put (_all_) (=);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Trim is needed to prevent SCAN from treating the spaces at the end of the string as the right most delimited value.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 May 2013 18:18:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extract-characters-in-a-field-cell/m-p/131735#M10725</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-05-07T18:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: Extract characters in a field/cell</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extract-characters-in-a-field-cell/m-p/131736#M10726</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The data in the column are pipe delimited.&amp;nbsp; Is it possible, within SAS EG 4.2, to do text-to-column based on "|" and ";"?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 May 2013 19:12:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extract-characters-in-a-field-cell/m-p/131736#M10726</guid>
      <dc:creator>jen123</dc:creator>
      <dc:date>2013-05-07T19:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: Extract characters in a field/cell</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extract-characters-in-a-field-cell/m-p/131737#M10727</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sure is. The below code will break your variable into X different observations, where X is the number of delimiters found within your string + 1. Note taht your string ends in ||||, so I am assuming that the values between tehse strings is a null (blank value) and that there is a blank value ending your string. If that is not true, this has to be changed a bit.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also note I defined newvars to be 9 as a hardcoded value, so if you are going to use this code on different strings that have variable length you have to make modifications to this to make sure your array is large enough to handle the split out.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data newdata;&lt;/P&gt;&lt;P&gt;set olddata;&lt;/P&gt;&lt;P&gt;string='18995|Pend-PrSu|18000_ProdSupReg|I|00102||||&amp;nbsp; ' (replace this with whatever you called your variable);&lt;/P&gt;&lt;P&gt;array newvars (9) $;&lt;/P&gt;&lt;P&gt;do i=1 to countw(string,'|','m');&lt;/P&gt;&lt;P&gt;newvar(i)=strip(scan(string,i,'|','m'));&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 07 May 2013 19:26:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extract-characters-in-a-field-cell/m-p/131737#M10727</guid>
      <dc:creator>Anotherdream</dc:creator>
      <dc:date>2013-05-07T19:26:18Z</dc:date>
    </item>
    <item>
      <title>Re: Extract characters in a field/cell</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extract-characters-in-a-field-cell/m-p/131738#M10728</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;*Here is the code you need &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data output ;&lt;/P&gt;&lt;P&gt;length newvars1-newvars11 $ 200;&lt;/P&gt;&lt;P&gt;set input;&lt;/P&gt;&lt;P&gt;array newvars (11) $;&lt;/P&gt;&lt;P&gt;do i=1 to countw(data,'|','m');&lt;/P&gt;&lt;P&gt;newvars(i)=strip(scan(data,i,'|','m'));&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 20 Mar 2015 03:53:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Extract-characters-in-a-field-cell/m-p/131738#M10728</guid>
      <dc:creator>jgfitton</dc:creator>
      <dc:date>2015-03-20T03:53:39Z</dc:date>
    </item>
  </channel>
</rss>

