<?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 a substring from a string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/extract-a-substring-from-a-string/m-p/82300#M17766</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It works great. Thanks, All&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 14 Jun 2012 13:06:16 GMT</pubDate>
    <dc:creator>QLi</dc:creator>
    <dc:date>2012-06-14T13:06:16Z</dc:date>
    <item>
      <title>extract a substring from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-a-substring-from-a-string/m-p/82292#M17758</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;All;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have data as the following.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data&amp;nbsp; have;&lt;/P&gt;&lt;P&gt;input string $40.;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;c 10 year fixed&lt;/P&gt;&lt;P&gt;n 30 year fixed&lt;/P&gt;&lt;P&gt;n 15 year fixed&lt;/P&gt;&lt;P&gt;sh nchfa fha 30 year&lt;/P&gt;&lt;P&gt;c 30 year fixed homepath&lt;/P&gt;&lt;P&gt;c 7 yr arm homepath&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to substring from a string to get the column like:&lt;/P&gt;&lt;P&gt;10 year&lt;/P&gt;&lt;P&gt;30 year&lt;/P&gt;&lt;P&gt;15 year&lt;/P&gt;&lt;P&gt;30 year&lt;/P&gt;&lt;P&gt;7 yr&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Jun 2012 20:26:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-a-substring-from-a-string/m-p/82292#M17758</guid>
      <dc:creator>QLi</dc:creator>
      <dc:date>2012-06-13T20:26:50Z</dc:date>
    </item>
    <item>
      <title>Re: extract a substring from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-a-substring-from-a-string/m-p/82293#M17759</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The ideal candidate for PRX regular expressions :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&lt;STRONG&gt;data&amp;nbsp; have;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&lt;STRONG&gt;input string $40.;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&lt;STRONG&gt;c 10 year fixed&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&lt;STRONG&gt;n 30 year fixed&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&lt;STRONG&gt;n 15 year fixed&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&lt;STRONG&gt;sh nchfa fha 30 year&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&lt;STRONG&gt;c 30 year fixed homepath&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&lt;STRONG&gt;c 7 yr arm homepath&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&lt;STRONG&gt;data want(keep=y);&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&lt;STRONG&gt;retain prxId;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&lt;STRONG&gt;set have;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&lt;STRONG&gt;if _n_ = 1 then prxId = prxparse("/\d+\s+y(ea)*r/i");&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&lt;STRONG&gt;call prxsubstr(prxId, string, pos, len);&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&lt;STRONG&gt;if pos&amp;gt;0 then do;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; y = substr(string,pos, len);&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&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; font-family: calibri, verdana, arial, sans-serif;"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&lt;STRONG&gt;proc print; run;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt; font-family: calibri, verdana, arial, sans-serif;"&gt;&lt;STRONG&gt;PG&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG Slightly improved the pattern &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Jun 2012 20:58:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-a-substring-from-a-string/m-p/82293#M17759</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2012-06-13T20:58:55Z</dc:date>
    </item>
    <item>
      <title>Re: extract a substring from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-a-substring-from-a-string/m-p/82294#M17760</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hi ... another idea ...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;data want;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;length y $10;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;set have;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;y = catx(' ',scan(substr(string,findc(string,,'d')),1),scan(substr(string,findc(string,,'d')),2));&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Jun 2012 21:24:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-a-substring-from-a-string/m-p/82294#M17760</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2012-06-13T21:24:35Z</dc:date>
    </item>
    <item>
      <title>Re: extract a substring from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-a-substring-from-a-string/m-p/82295#M17761</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;how about:&lt;/P&gt;&lt;P&gt;data&amp;nbsp; have;&lt;/P&gt;&lt;P&gt;input string $40.;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;c 10 year fixed&lt;/P&gt;&lt;P&gt;n 30 year fixed&lt;/P&gt;&lt;P&gt;n 15 year fixed&lt;/P&gt;&lt;P&gt;sh nchfa fha 30 year&lt;/P&gt;&lt;P&gt;c 30 year fixed homepath&lt;/P&gt;&lt;P&gt;c 7 yr arm homepath&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;data want(keep=new:);&lt;/P&gt;&lt;P&gt;&amp;nbsp; length new_string $ 7;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; new_string=catx(' ',compress(string,,'kd'),'year');&lt;/P&gt;&lt;P&gt;&amp;nbsp; proc print;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Linlin&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 13 Jun 2012 23:06:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-a-substring-from-a-string/m-p/82295#M17761</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-06-13T23:06:13Z</dc:date>
    </item>
    <item>
      <title>Re: extract a substring from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-a-substring-from-a-string/m-p/82296#M17762</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Linlin, seems like QLi wants 'yr' on the last line. &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;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Jun 2012 00:34:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-a-substring-from-a-string/m-p/82296#M17762</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2012-06-14T00:34:22Z</dc:date>
    </item>
    <item>
      <title>Re: extract a substring from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-a-substring-from-a-string/m-p/82297#M17763</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;PG,&amp;nbsp; &lt;/P&gt;&lt;P&gt;In that case, my code will not work.&lt;img id="smileysad" class="emoticon emoticon-smileysad" src="https://communities.sas.com/i/smilies/16x16_smiley-sad.png" alt="Smiley Sad" title="Smiley Sad" /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Jun 2012 01:47:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-a-substring-from-a-string/m-p/82297#M17763</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-06-14T01:47:39Z</dc:date>
    </item>
    <item>
      <title>Re: extract a substring from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-a-substring-from-a-string/m-p/82298#M17764</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Another PRX Function.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;data&amp;nbsp; have;
input string $40.;
datalines;
c 10 year fixed
n 30 year fixed
n 15 year fixed
sh nchfa fha 30 year
c 30 year fixed homepath
c 7 yr arm homepath
;
run;
data want(drop=pid);
 set have;
 length year $ 20;
 retain pid;
 if _n_ eq 1 then pid=prxparse('/(\d+\s*(year|yr))/i');
 if prxmatch(pid,string) then year=prxposn(pid,1,string);
run; 

&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ksharp&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Jun 2012 02:21:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-a-substring-from-a-string/m-p/82298#M17764</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2012-06-14T02:21:31Z</dc:date>
    </item>
    <item>
      <title>Re: extract a substring from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-a-substring-from-a-string/m-p/82299#M17765</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Very nice Ksharp!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Jun 2012 02:34:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-a-substring-from-a-string/m-p/82299#M17765</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2012-06-14T02:34:09Z</dc:date>
    </item>
    <item>
      <title>Re: extract a substring from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/extract-a-substring-from-a-string/m-p/82300#M17766</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It works great. Thanks, All&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 14 Jun 2012 13:06:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/extract-a-substring-from-a-string/m-p/82300#M17766</guid>
      <dc:creator>QLi</dc:creator>
      <dc:date>2012-06-14T13:06:16Z</dc:date>
    </item>
  </channel>
</rss>

