<?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: Remove all text before 2nd (or 3rd) ('_') &amp;amp; all text after the 1st ('_') backwards from the in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Remove-all-text-before-2nd-or-3rd-amp-all-text-after-the-1st/m-p/820198#M323716</link>
    <description>&lt;P&gt;You are right. My request was not clarifying the "2nd or 3rd". My apologies for this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I meant was either the second or the 3rd underscore based on the condition that the previous block of characters is either&amp;nbsp;&amp;nbsp;U8 ,&amp;nbsp;FT,&amp;nbsp;7P&amp;nbsp; (just before the 2nd "_")&lt;/P&gt;&lt;P&gt;or&amp;nbsp; SA, CD, BF just before the 3rd "_".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this clarifies my question.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;</description>
    <pubDate>Fri, 24 Jun 2022 07:02:06 GMT</pubDate>
    <dc:creator>Zeus_Olympus</dc:creator>
    <dc:date>2022-06-24T07:02:06Z</dc:date>
    <item>
      <title>Remove all text before 2nd (or 3rd) ('_') &amp; all text after the 1st ('_') backwards from the end</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-all-text-before-2nd-or-3rd-amp-all-text-after-the-1st/m-p/820022#M323639</link>
      <description>&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have text string values like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;TR_U8_FORTE_BDERT_GT_RPJ&lt;/P&gt;&lt;P&gt;GD_FT_LAMAN_TRITE_SRTI_GT_RPJ&lt;/P&gt;&lt;P&gt;VB_7P_VELON_SUTI_RPJ&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and I need :&lt;/P&gt;&lt;P&gt;FORTE_BDERT_GT&lt;/P&gt;&lt;P&gt;LAMAN_TRITE_SRTI_GT&lt;/P&gt;&lt;P&gt;VELON_SUTI&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried SCAN function without success.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would appreciate your advice.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 14:16:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-all-text-before-2nd-or-3rd-amp-all-text-after-the-1st/m-p/820022#M323639</guid>
      <dc:creator>Zeus_Olympus</dc:creator>
      <dc:date>2022-06-23T14:16:34Z</dc:date>
    </item>
    <item>
      <title>Re: Remove all text before 2nd (or 3rd) ('_') &amp; all text after the 1st ('_') backwards from the</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-all-text-before-2nd-or-3rd-amp-all-text-after-the-1st/m-p/820024#M323640</link>
      <description>&lt;P&gt;What is the logic here?&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 14:17:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-all-text-before-2nd-or-3rd-amp-all-text-after-the-1st/m-p/820024#M323640</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-06-23T14:17:48Z</dc:date>
    </item>
    <item>
      <title>Re: Remove all text before 2nd (or 3rd) ('_') &amp; all text after the 1st ('_') backwards from the</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-all-text-before-2nd-or-3rd-amp-all-text-after-the-1st/m-p/820029#M323642</link>
      <description>&lt;P&gt;Here is a quick way to get the results you are looking for.&lt;/P&gt;
&lt;P&gt;data test ;&lt;BR /&gt;input textstr $31.;&lt;BR /&gt;newtextstr=substr(textstr,1,length(textstr)-4);&lt;BR /&gt;newtextstr=substr(newtextstr,7);&lt;BR /&gt;datalines ;&lt;BR /&gt;TR_U8_FORTE_BDERT_GT_RPJ&lt;BR /&gt;GD_FT_LAMAN_TRITE_SRTI_GT_RPJ&lt;BR /&gt;VB_7P_VELON_SUTI_RPJ&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 15:13:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-all-text-before-2nd-or-3rd-amp-all-text-after-the-1st/m-p/820029#M323642</guid>
      <dc:creator>CarmineVerrell</dc:creator>
      <dc:date>2022-06-23T15:13:56Z</dc:date>
    </item>
    <item>
      <title>Re: Remove all text before 2nd (or 3rd) ('_') &amp; all text after the 1st ('_') backwards from the</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-all-text-before-2nd-or-3rd-amp-all-text-after-the-1st/m-p/820035#M323644</link>
      <description>&lt;P&gt;You will have to describe in terms of things that exist in the data when you want "before 2nd" and "before 3rd" removed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This works for your example:&lt;/P&gt;
&lt;PRE&gt;data have;
   input str $50.;
datalines;
TR_U8_FORTE_BDERT_GT_RPJ
GD_FT_LAMAN_TRITE_SRTI_GT_RPJ
VB_7P_VELON_SUTI_RPJ
;

data want;
   set have;
   length newstr $ 50.;
   do i= 3 to (countw(str,'_') - 1);
      newstr = catx('_',newstr,scan(str,i,'_'));
   end;&lt;BR /&gt;   drop i;
run;&lt;/PRE&gt;
&lt;P&gt;This works for "remove 2" by starting at the 3rd "word" delimited by the _ character. You would replace the 3 with 4 in the Do i=3 to remove 3 (start at 4th word). The Countw function tells us how many "words" separated by the _ there are so we stop getting before the last.&lt;/P&gt;
&lt;P&gt;Catx inserts the _ between the words pulled using SCAN, which only treats the _ as delimiter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Caution: if there are ever only 3 (or 4) "words" you will get an empty string result. If you have fewer than 3 you will generate an error in the Do loop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You would provide additional conditions, which you have not even hinted at, for whether to use the "Do i=3" or "Do i=4" version. Probably some sort of test in an IF statement before the Do.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 14:48:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-all-text-before-2nd-or-3rd-amp-all-text-after-the-1st/m-p/820035#M323644</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-06-23T14:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: Remove all text before 2nd (or 3rd) ('_') &amp; all text after the 1st ('_') backwards from the</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-all-text-before-2nd-or-3rd-amp-all-text-after-the-1st/m-p/820198#M323716</link>
      <description>&lt;P&gt;You are right. My request was not clarifying the "2nd or 3rd". My apologies for this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I meant was either the second or the 3rd underscore based on the condition that the previous block of characters is either&amp;nbsp;&amp;nbsp;U8 ,&amp;nbsp;FT,&amp;nbsp;7P&amp;nbsp; (just before the 2nd "_")&lt;/P&gt;&lt;P&gt;or&amp;nbsp; SA, CD, BF just before the 3rd "_".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this clarifies my question.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2022 07:02:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-all-text-before-2nd-or-3rd-amp-all-text-after-the-1st/m-p/820198#M323716</guid>
      <dc:creator>Zeus_Olympus</dc:creator>
      <dc:date>2022-06-24T07:02:06Z</dc:date>
    </item>
    <item>
      <title>Re: Remove all text before 2nd (or 3rd) ('_') &amp; all text after the 1st ('_') backwards from the</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-all-text-before-2nd-or-3rd-amp-all-text-after-the-1st/m-p/820202#M323717</link>
      <description>&lt;P&gt;Below an option if I understand the requirement right.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input textstr $60.;
  datalines;
TR_U8_FORTE_BDERT_GT_RPJ
GD_FT_LAMAN_TRITE_SRTI_GT_RPJ
VB_7P_VELON_SUTI_RPJ
11_222_A_99
11_222_99
11_99
11
;

data want;
  set have;
  length want_str $60;
  if countc(textstr,'_')&amp;gt;2 then
    want_str=prxchange('s/^[^_]+_[^_]+_(.+)_[^_]+$/$1/oi',1,strip(textstr));
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1656060577703.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72712iF618B0B0792E3EFD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1656060577703.png" alt="Patrick_0-1656060577703.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2022 08:49:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-all-text-before-2nd-or-3rd-amp-all-text-after-the-1st/m-p/820202#M323717</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2022-06-24T08:49:46Z</dc:date>
    </item>
    <item>
      <title>Re: Remove all text before 2nd (or 3rd) ('_') &amp; all text after the 1st ('_') backwards from the</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Remove-all-text-before-2nd-or-3rd-amp-all-text-after-the-1st/m-p/820223#M323726</link>
      <description>&lt;PRE&gt;data have;
   input str $50.;
datalines;
TR_U8_FORTE_BDERT_GT_RPJ
GD_FT_LAMAN_TRITE_SRTI_GT_RPJ
VB_7P_VELON_SUTI_RPJ
;

data want;
 set have;
want=prxchange('s/^[^_]+_[^_]+_|_[^_]+$//',-1,strip(str));
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Jun 2022 12:09:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Remove-all-text-before-2nd-or-3rd-amp-all-text-after-the-1st/m-p/820223#M323726</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-06-24T12:09:31Z</dc:date>
    </item>
  </channel>
</rss>

