<?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: How to remove the prefix and suffix at one step? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-prefix-and-suffix-at-one-step/m-p/557345#M155357</link>
    <description>&lt;P&gt;Hi, novinosrin,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for providing more solutions! These versatile ways will serve many kinds of scenarios. Thank you!&lt;/P&gt;</description>
    <pubDate>Thu, 09 May 2019 02:14:15 GMT</pubDate>
    <dc:creator>leehsin</dc:creator>
    <dc:date>2019-05-09T02:14:15Z</dc:date>
    <item>
      <title>How to remove the prefix and suffix at one step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-prefix-and-suffix-at-one-step/m-p/557169#M155283</link>
      <description>&lt;P&gt;Hi, I wanted to extract pact of the characters from a string which has delimiter '_'. The string is like this:&lt;BR /&gt;&lt;BR /&gt;'abcd_ggg_fff_1234'&lt;BR /&gt;&lt;BR /&gt;My question is: is there a single step to get 'ggg_fff" from that string, or have to do it in two steps?&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2019 15:44:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-prefix-and-suffix-at-one-step/m-p/557169#M155283</guid>
      <dc:creator>leehsin</dc:creator>
      <dc:date>2019-05-08T15:44:07Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove the prefix and suffix at one step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-prefix-and-suffix-at-one-step/m-p/557174#M155285</link>
      <description>&lt;P&gt;please try perl regular expression&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
x='abcd_ggg_fff_1234';
y=prxchange('s/(\w+)(ggg_fff)(.\d+)/$2/',-1,x);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 May 2019 16:00:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-prefix-and-suffix-at-one-step/m-p/557174#M155285</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-05-08T16:00:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove the prefix and suffix at one step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-prefix-and-suffix-at-one-step/m-p/557179#M155286</link>
      <description>&lt;P&gt;Thanks, Jagadishkatam! But I have more strings with different middle parts:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;'abcd_ggg_fff_1234'&lt;/P&gt;&lt;P&gt;'abcd_ttt_www_1234'&lt;/P&gt;&lt;P&gt;'qadc_hhh_lll_4321'&lt;/P&gt;&lt;P&gt;'dret_eee_1278'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just want to do the general removal of prefix and suffix for all strings, not for a specific one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2019 16:07:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-prefix-and-suffix-at-one-step/m-p/557179#M155286</guid>
      <dc:creator>leehsin</dc:creator>
      <dc:date>2019-05-08T16:07:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove the prefix and suffix at one step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-prefix-and-suffix-at-one-step/m-p/557180#M155287</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/215142"&gt;@leehsin&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Call scan&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data have;
input str $30.;
cards;
abcd_ggg_fff_1234
abcd_ttt_www_1234
qadc_hhh_lll_4321
dret_eee_1278
;


data want;
set have; 
call scan(str, 1, position, length,'_');
substr(str,1,length+1)=' ';
call scan(str, -1, position, length,'_');
substr(str,position-1)=' ';
drop position length;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 May 2019 16:15:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-prefix-and-suffix-at-one-step/m-p/557180#M155287</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-05-08T16:15:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove the prefix and suffix at one step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-prefix-and-suffix-at-one-step/m-p/557183#M155289</link>
      <description>&lt;P&gt;Or&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;

data have;
input str $30.;
cards;
abcd_ggg_fff_1234
abcd_ttt_www_1234
qadc_hhh_lll_4321
dret_eee_1278
;


data want;
set have; 
call scan(str, 1, p, l,'_');
call scan(str, -1, position, length,'_');
want=substr(str,l+2,position-(l+3));
drop p: l:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 May 2019 16:23:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-prefix-and-suffix-at-one-step/m-p/557183#M155289</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-05-08T16:23:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove the prefix and suffix at one step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-prefix-and-suffix-at-one-step/m-p/557185#M155291</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input text :$100.;
if countw(text,'_')=4 then y=prxchange('s/(\w+\_)(\w+\_\w+)(\_\d+)/$2/',-1,text);
else if countw(text,'_')=3 then y=prxchange('s/(\w+\_)(\w+)(\_\d+)/$2/',-1,text);
cards;
abcd_ggg_fff_1234
abcd_ttt_www_1234
qadc_hhh_lll_4321
dret_eee_1278
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 May 2019 16:31:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-prefix-and-suffix-at-one-step/m-p/557185#M155291</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2019-05-08T16:31:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove the prefix and suffix at one step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-prefix-and-suffix-at-one-step/m-p/557186#M155292</link>
      <description>&lt;P&gt;Hi, novinosrin, thanks for the solution. So, one step is not feasible. How about I want to keep both the original string and the new string?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2019 16:35:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-prefix-and-suffix-at-one-step/m-p/557186#M155292</guid>
      <dc:creator>leehsin</dc:creator>
      <dc:date>2019-05-08T16:35:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove the prefix and suffix at one step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-prefix-and-suffix-at-one-step/m-p/557187#M155293</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/215142"&gt;@leehsin&lt;/a&gt;&amp;nbsp; My second version gives you both. Please review&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2019 16:36:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-prefix-and-suffix-at-one-step/m-p/557187#M155293</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-05-08T16:36:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove the prefix and suffix at one step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-prefix-and-suffix-at-one-step/m-p/557189#M155294</link>
      <description>&lt;P&gt;Great! This solved my problem! Thank you so much!&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2019 16:42:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-prefix-and-suffix-at-one-step/m-p/557189#M155294</guid>
      <dc:creator>leehsin</dc:creator>
      <dc:date>2019-05-08T16:42:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove the prefix and suffix at one step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-prefix-and-suffix-at-one-step/m-p/557191#M155295</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/215142"&gt;@leehsin&lt;/a&gt;&amp;nbsp; Just to accept your challenge, here is a one step solution. It's not any faster or better but I loved your question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input str $30.;
cards;
abcd_ggg_fff_1234
abcd_ttt_www_1234
qadc_hhh_lll_4321
dret_eee_1278
;


data want;
set have; 
want=substr(str,index(str,'_')+1, findc(str,'_','B')- (index(str,'_')+1));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, Call scan is by far much faster than a regular expression for a simple problem like this unless your pattern really needs a regex&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2019 16:47:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-prefix-and-suffix-at-one-step/m-p/557191#M155295</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-05-08T16:47:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove the prefix and suffix at one step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-prefix-and-suffix-at-one-step/m-p/557194#M155296</link>
      <description>&lt;P&gt;Jagadishkatam, yours is another good solution. Maybe more codes needed if I want to automatically detect the numbers for countw to use.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2019 16:46:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-prefix-and-suffix-at-one-step/m-p/557194#M155296</guid>
      <dc:creator>leehsin</dc:creator>
      <dc:date>2019-05-08T16:46:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove the prefix and suffix at one step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-prefix-and-suffix-at-one-step/m-p/557195#M155297</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/215142"&gt;@leehsin&lt;/a&gt;&amp;nbsp; &amp;nbsp;This linear approach is pretty quick&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input str $30.;
cards;
abcd_ggg_fff_1234
abcd_ttt_www_1234
qadc_hhh_lll_4321
dret_eee_1278
;

data want;
set have;
length want $30;
do _n_=2 to countw(str,'_')-1;
want=catx('_',want,scan(str,_n_,'_'));
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 May 2019 16:56:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-prefix-and-suffix-at-one-step/m-p/557195#M155297</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-05-08T16:56:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove the prefix and suffix at one step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-prefix-and-suffix-at-one-step/m-p/557345#M155357</link>
      <description>&lt;P&gt;Hi, novinosrin,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for providing more solutions! These versatile ways will serve many kinds of scenarios. Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 09 May 2019 02:14:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-the-prefix-and-suffix-at-one-step/m-p/557345#M155357</guid>
      <dc:creator>leehsin</dc:creator>
      <dc:date>2019-05-09T02:14:15Z</dc:date>
    </item>
  </channel>
</rss>

