<?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 SCAN(SUBSTRING) in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SCAN-SUBSTRING/m-p/180692#M13803</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How do I write a function that will search for a character within a string then pull the 6 digits after the character including the character?&lt;/P&gt;&lt;P&gt;Ex:&lt;/P&gt;&lt;P&gt;0000M123450000&lt;/P&gt;&lt;P&gt;11M12345898989&lt;/P&gt;&lt;P&gt;222222m1234500&lt;/P&gt;&lt;P&gt;0M12345547&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Each data line is different in length, but the output (work) should be&lt;/P&gt;&lt;P&gt;M12345&lt;/P&gt;&lt;P&gt;M12345&lt;/P&gt;&lt;P&gt;M12345&lt;/P&gt;&lt;P&gt;M12345&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Keep in mind the character can be lowercase or uppercase. &lt;/P&gt;&lt;P&gt;In this situation the value is "M" and I'm looking for 6 digits including the M.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance.....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 15 Apr 2014 17:12:32 GMT</pubDate>
    <dc:creator>Dsrountree</dc:creator>
    <dc:date>2014-04-15T17:12:32Z</dc:date>
    <item>
      <title>SCAN(SUBSTRING)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SCAN-SUBSTRING/m-p/180692#M13803</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How do I write a function that will search for a character within a string then pull the 6 digits after the character including the character?&lt;/P&gt;&lt;P&gt;Ex:&lt;/P&gt;&lt;P&gt;0000M123450000&lt;/P&gt;&lt;P&gt;11M12345898989&lt;/P&gt;&lt;P&gt;222222m1234500&lt;/P&gt;&lt;P&gt;0M12345547&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Each data line is different in length, but the output (work) should be&lt;/P&gt;&lt;P&gt;M12345&lt;/P&gt;&lt;P&gt;M12345&lt;/P&gt;&lt;P&gt;M12345&lt;/P&gt;&lt;P&gt;M12345&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Keep in mind the character can be lowercase or uppercase. &lt;/P&gt;&lt;P&gt;In this situation the value is "M" and I'm looking for 6 digits including the M.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance.....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Apr 2014 17:12:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SCAN-SUBSTRING/m-p/180692#M13803</guid>
      <dc:creator>Dsrountree</dc:creator>
      <dc:date>2014-04-15T17:12:32Z</dc:date>
    </item>
    <item>
      <title>Re: SCAN(SUBSTRING)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SCAN-SUBSTRING/m-p/180693#M13804</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Substr( inputstring, verify( inputstring, '012345679''), 6)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That VERIFY() function returns the position of the first character of the first parameter that is not in the second parameter. So in the example above it points to any non-numeric which means that M.&lt;/P&gt;&lt;P&gt;it is just about the most efficient of these string hunting functiins&lt;/P&gt;&lt;P&gt;(I am told)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Apr 2014 17:38:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SCAN-SUBSTRING/m-p/180693#M13804</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2014-04-15T17:38:07Z</dc:date>
    </item>
    <item>
      <title>Re: SCAN(SUBSTRING)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SCAN-SUBSTRING/m-p/180694#M13805</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Use a combination of find and substring. &lt;/P&gt;&lt;P&gt;You may need to play with the -1 and or 6 to get what you want, but this should be close (untested).&lt;/P&gt;&lt;P&gt;There's also Perl Expressions, but I avoid those &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;WANT = substr(word,findc(word, "M", 'TI')-1, 6);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Apr 2014 17:38:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SCAN-SUBSTRING/m-p/180694#M13805</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-04-15T17:38:30Z</dc:date>
    </item>
    <item>
      <title>Re: SCAN(SUBSTRING)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SCAN-SUBSTRING/m-p/180695#M13806</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;newcol=upper(substring(oldcol,find(oldcol,'m',i),6));&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Apr 2014 17:39:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SCAN-SUBSTRING/m-p/180695#M13806</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2014-04-15T17:39:03Z</dc:date>
    </item>
    <item>
      <title>Re: SCAN(SUBSTRING)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SCAN-SUBSTRING/m-p/180696#M13807</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Adjusting the value to -0 will account for the first position.&lt;/P&gt;&lt;P&gt;substr(t1.'PACKAGE ID'n,findc(t1.'PACKAGE ID'n, "M", 'TI')-0, 9)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks Everyone - very Helpful &lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://communities.sas.com/i/smilies/16x16_smiley-wink.png" alt="Smiley Wink" title="Smiley Wink" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Apr 2014 18:24:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SCAN-SUBSTRING/m-p/180696#M13807</guid>
      <dc:creator>Dsrountree</dc:creator>
      <dc:date>2014-04-15T18:24:24Z</dc:date>
    </item>
    <item>
      <title>Re: SCAN(SUBSTRING)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SCAN-SUBSTRING/m-p/180697#M13808</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You might need to use IF/THEN logic to handle cases that do not meet the pattern.&lt;/P&gt;&lt;P&gt;For this simple case of only one letter you could use the INDEXC() function to handle matching case.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;loc = indexc(STRING,'mM');&lt;/P&gt;&lt;P&gt;if 0 &amp;lt; loc &amp;lt;= length(string)-5 then NEW = substr(STRING,loc,6) ;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Apr 2014 18:31:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SCAN-SUBSTRING/m-p/180697#M13808</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-04-15T18:31:58Z</dc:date>
    </item>
    <item>
      <title>Re: SCAN(SUBSTRING)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SCAN-SUBSTRING/m-p/180698#M13809</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It shouldn't need conditional logic like IF or CASE when you are using FINDc or VERIFY.&lt;/P&gt;&lt;P&gt;Just extend the strings like&lt;/P&gt;&lt;P&gt;substr( inputstring !! "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ", verify( inputstring !! "M", '1234567890'), 6 )&lt;/P&gt;&lt;P&gt;Or,&lt;/P&gt;&lt;P&gt;Substr( t1.'PACKAGE ID'n !! '&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ', findc(&amp;nbsp; t1.'PACKAGE ID'n !! 'M', 'ti' ), 9 )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;by appending enough blanks and an M to the input string you can guarantee therr enough characters to extract from&amp;nbsp;&amp;nbsp; and an M will always be found in the dearch&amp;nbsp;&amp;nbsp;&amp;nbsp; even if it is after the original 'package ID'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Nor should you need that -0 .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Was it 9 or 6 characters you wanted to extract?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Apr 2014 22:25:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SCAN-SUBSTRING/m-p/180698#M13809</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2014-04-15T22:25:32Z</dc:date>
    </item>
    <item>
      <title>Re: SCAN(SUBSTRING)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SCAN-SUBSTRING/m-p/180699#M13810</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It seems that 'M/m' is only alpha character &lt;SPAN style="color: #000000; font-family: arial, 'Arial Unicode MS', geneva, 'Lucida Grande', sans-serif;"&gt;in string, so:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; font-family: arial, 'Arial Unicode MS', geneva, 'Lucida Grande', sans-serif;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #000000; font-family: arial, 'Arial Unicode MS', geneva, 'Lucida Grande', sans-serif;"&gt;substr(string,anyalpha(string),6)&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Apr 2014 00:21:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SCAN-SUBSTRING/m-p/180699#M13810</guid>
      <dc:creator>slchen</dc:creator>
      <dc:date>2014-04-16T00:21:20Z</dc:date>
    </item>
    <item>
      <title>Re: SCAN(SUBSTRING)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SCAN-SUBSTRING/m-p/180700#M13811</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I hate to add to answers that are already plentiful and working, but this approach seemed interesting:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;length newvar $ 6;&lt;/P&gt;&lt;P&gt;newvar = 'M' || scan(word, 2, 'Mm');&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It will, however, return "M" with no digits following if the incoming word doesn't contain any M/M.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Apr 2014 12:49:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SCAN-SUBSTRING/m-p/180700#M13811</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2014-04-16T12:49:00Z</dc:date>
    </item>
    <item>
      <title>Re: SCAN(SUBSTRING)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SCAN-SUBSTRING/m-p/180701#M13812</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;But I like Perl Regular Expression.&lt;/P&gt;&lt;P&gt;For every pure programmer like Java , C++ ,they all use it to process string type variables . I recommend you to learn it, you will get a powerful tool .&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data have;
input x : $40.;
cards;
0000M123450000
11M12345898989
222222m1234500
0M12345547
;
run;
data want;
 set have;
 xx=prxchange('s/.*([Mm]\d{5}).*/$1/',-1,x);
run;

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Apr 2014 13:05:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SCAN-SUBSTRING/m-p/180701#M13812</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-04-16T13:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: SCAN(SUBSTRING)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SCAN-SUBSTRING/m-p/180702#M13813</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks again Gentlemen - i love learning new methods to parse data...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Keshan - I'll take a look at it, but the last time I touched Java was back in my college days.&lt;/P&gt;&lt;P&gt;Keep in mind - I'm new to this SAS thing, but love to learn..............&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Apr 2014 14:17:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SCAN-SUBSTRING/m-p/180702#M13813</guid>
      <dc:creator>Dsrountree</dc:creator>
      <dc:date>2014-04-16T14:17:39Z</dc:date>
    </item>
    <item>
      <title>Re: SCAN(SUBSTRING)</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SCAN-SUBSTRING/m-p/180703#M13814</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You are going to love &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Perl Regular Expression.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 16 Apr 2014 14:52:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SCAN-SUBSTRING/m-p/180703#M13814</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-04-16T14:52:37Z</dc:date>
    </item>
  </channel>
</rss>

