<?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 do I trim the piece to the right of the last underscore? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93100#M19636</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not at my computer w/ sas to work out the syntax, but assuming the number of "-"s is variable, then you can use the reverse function, find the first "_", and take everything after it...then reverse it again.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 30 Mar 2013 15:40:22 GMT</pubDate>
    <dc:creator>DBailey</dc:creator>
    <dc:date>2013-03-30T15:40:22Z</dc:date>
    <item>
      <title>how do I trim the piece to the right of the last underscore?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93095#M19631</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I just want: &lt;STRONG&gt;"IR_MX_GOVT_BFV_MXN" , &lt;/STRONG&gt;or trim off the piece to the right of the last underscore, including the underscore.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;How do I do that?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; t;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;crv=&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 11pt;"&gt;'IR_MX_GOVT_BFV_MXN_7Y'&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 30 Mar 2013 00:54:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93095#M19631</guid>
      <dc:creator>ZRick</dc:creator>
      <dc:date>2013-03-30T00:54:15Z</dc:date>
    </item>
    <item>
      <title>Re: how do I trim the piece to the right of the last underscore?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93096#M19632</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I usually use SAS functions like SCAN and SUBSTR, but you can probably get someone to show you a regular expression syntax.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data t;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; crv='IR_MX_GOVT_BFV_MXN_7Y';&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; if index(crv,'_') then want = substr(crv,1,length(crv)-length(scan(crv,-1,'_'))-1);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; put (crv want) (=/);&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;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 30 Mar 2013 00:58:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93096#M19632</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-03-30T00:58:46Z</dc:date>
    </item>
    <item>
      <title>Re: how do I trim the piece to the right of the last underscore?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93097#M19633</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks so much, Tom.&lt;/P&gt;&lt;P&gt;Do I need to use trim(left(var)) to trim off the blanks?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, why do you put "if index(crv,'_') then" as the condition logic?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 30 Mar 2013 01:05:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93097#M19633</guid>
      <dc:creator>ZRick</dc:creator>
      <dc:date>2013-03-30T01:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: how do I trim the piece to the right of the last underscore?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93098#M19634</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;TRIM() is meaningless in this situation as LENGTH() and SAS assignment to character variables will ignore and append spaces, respectively.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I added the IF because I was worried about what it would do when there were no underscores in the value.&amp;nbsp; Try it and see what happens.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 30 Mar 2013 01:20:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93098#M19634</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-03-30T01:20:59Z</dc:date>
    </item>
    <item>
      <title>Re: how do I trim the piece to the right of the last underscore?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93099#M19635</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Another approach is to "call scan":&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data t;&lt;/P&gt;&lt;P&gt;crv='IR_MX_GOVT_BFV_MXN_7Y';&lt;/P&gt;&lt;P&gt;call scan(crv,-1,_p,_l,'_');&lt;/P&gt;&lt;P&gt;want=substr(crv,1,_p-2);&lt;/P&gt;&lt;P&gt;put (crv want) (=/);&lt;/P&gt;&lt;P&gt;drop _:;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 30 Mar 2013 14:34:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93099#M19635</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2013-03-30T14:34:47Z</dc:date>
    </item>
    <item>
      <title>Re: how do I trim the piece to the right of the last underscore?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93100#M19636</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not at my computer w/ sas to work out the syntax, but assuming the number of "-"s is variable, then you can use the reverse function, find the first "_", and take everything after it...then reverse it again.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 30 Mar 2013 15:40:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93100#M19636</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2013-03-30T15:40:22Z</dc:date>
    </item>
    <item>
      <title>Re: how do I trim the piece to the right of the last underscore?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93101#M19637</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;
&lt;P&gt;DBailey wrote:&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I'm not at my computer w/ sas to work out the syntax, but assuming the number of "-"s is variable, then you can use the reverse function, find the first "_", and take everything after it...then reverse it again.&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;Instead of fiddling with reverse just search from the right.&amp;nbsp; My question is what should be assigned when there are no underscores.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV style="font-family: Courier New; font-size: 11pt;"&gt;&lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;data&lt;/STRONG&gt; &lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;_null_&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;do&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; crv=&lt;/SPAN&gt;&lt;SPAN style="color: #800080; background-color: #ffffff;"&gt;'IR_MX_GOVT_BFV_MXN_7Y'&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="color: #800080; background-color: #ffffff;"&gt;'IRMXGOVTBFVXN7Y'&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; want2= substrN(crv,&lt;/SPAN&gt;&lt;STRONG style="color: #008080; background-color: #ffffff;"&gt;1&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;,find(crv,&lt;/SPAN&gt;&lt;SPAN style="color: #800080; background-color: #ffffff;"&gt;'_'&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;,-length(crv))-&lt;/SPAN&gt;&lt;STRONG style="color: #008080; background-color: #ffffff;"&gt;1&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;);&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;put&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; (crv want:) (=/);&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;call&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt; missing(of want:);&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="color: #0000ff; background-color: #ffffff;"&gt;end&lt;/SPAN&gt;; &lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;STRONG style="color: #000080; background-color: #ffffff;"&gt;run&lt;/STRONG&gt;&lt;SPAN style="color: #000000; background-color: #ffffff;"&gt;;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 30 Mar 2013 15:48:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93101#M19637</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2013-03-30T15:48:55Z</dc:date>
    </item>
    <item>
      <title>Re: how do I trim the piece to the right of the last underscore?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93102#M19638</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can also kill a fly with a bazooka :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data t;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;crv='IR_MX_GOVT_BFV_MXN_7Y';&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;want = prxchange("s/(.*)_[^_]*$/\1/", 1, crv);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;put (crv want) (=/);&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It also works as required when there is no underscore. - PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 30 Mar 2013 16:03:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93102#M19638</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2013-03-30T16:03:52Z</dc:date>
    </item>
    <item>
      <title>Re: how do I trim the piece to the right of the last underscore?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93103#M19639</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote" modifiedtitle="true"&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;It also works as required when there is no underscore. - PG&lt;/P&gt;

&lt;/PRE&gt;&lt;P&gt; How do you know?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 30 Mar 2013 16:46:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93103#M19639</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2013-03-30T16:46:02Z</dc:date>
    </item>
    <item>
      <title>Re: how do I trim the piece to the right of the last underscore?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93104#M19640</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;From first principles. I also tested...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;14&amp;nbsp;&amp;nbsp; data t;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12pt;"&gt;15&amp;nbsp;&amp;nbsp; crv='IR_MX_GOVT_BFV_MXN_7Y';&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12pt;"&gt;16&amp;nbsp;&amp;nbsp; want = prxchange("s/(.*)_[^_]*$/\1/",1,crv);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12pt;"&gt;17&amp;nbsp;&amp;nbsp; put (crv want) (=/);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12pt;"&gt;18&amp;nbsp;&amp;nbsp; crv='IRMXGOVTBFVMXN7Y';&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12pt;"&gt;19&amp;nbsp;&amp;nbsp; want = prxchange("s/(.*)_[^_]*$/\1/",1,crv);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12pt;"&gt;20&amp;nbsp;&amp;nbsp; put (crv want) (=/);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12pt;"&gt;21&amp;nbsp;&amp;nbsp; run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12pt;"&gt;crv=IR_MX_GOVT_BFV_MXN_7Y&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12pt;"&gt;want=IR_MX_GOVT_BFV_MXN&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;crv=IRMXGOVTBFVMXN7Y&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12pt;"&gt;want=IRMXGOVTBFVMXN7Y&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;... looks ok to me.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;PG&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 30 Mar 2013 19:17:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93104#M19640</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2013-03-30T19:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: how do I trim the piece to the right of the last underscore?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93105#M19641</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;
&lt;P&gt;ZRick wrote:&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;I just want: &lt;STRONG&gt;"IR_MX_GOVT_BFV_MXN" , &lt;/STRONG&gt;or trim off the piece to the right of the last underscore, including the underscore.&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;How do I do that?&lt;/P&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG style="color: navy; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt; t;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;crv=&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: purple; font-size: 11pt;"&gt;'IR_MX_GOVT_BFV_MXN_7Y'&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG style="color: navy; font-size: 11pt; background: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 11pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another regular expression solution:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote" modifiedtitle="true"&gt;
&lt;P style="font-size: 14px; font-family: 'Courier New'; color: #011993;"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt; t;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="font-size: 14px; font-family: 'Courier New'; color: #942193;"&gt;&lt;SPAN style="color: #000000;"&gt;crv=&lt;/SPAN&gt;'IR_MX_GOVT_BFV_MXN_7Y'&lt;SPAN style="color: #000000;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="font-size: 14px; font-family: 'Courier New'; color: #008f00;"&gt;* crv='IRMXGOVTBFVMXN7Y';&lt;/P&gt;
&lt;P style="font-size: 14px; font-family: 'Courier New';"&gt;new1a=prxchange(&lt;SPAN style="color: #942193;"&gt;"s/^(.*)_(.*)$/\1/o"&lt;/SPAN&gt;,-&lt;SPAN style="color: #009193;"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;,crv);&lt;/P&gt;
&lt;P style="font-size: 14px; font-family: 'Courier New';"&gt;new1b=prxchange(&lt;SPAN style="color: #942193;"&gt;"s/^(.*)_(.*)$/\2/o"&lt;/SPAN&gt;,-&lt;SPAN style="color: #009193;"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;,crv);&lt;/P&gt;
&lt;P style="font-size: 14px; font-family: 'Courier New';"&gt;new2a=prxchange(&lt;SPAN style="color: #942193;"&gt;"s/^(.*?)_(.*)$/\1/o"&lt;/SPAN&gt;,-&lt;SPAN style="color: #009193;"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;,crv);&lt;/P&gt;
&lt;P style="font-size: 14px; font-family: 'Courier New';"&gt;new2b=prxchange(&lt;SPAN style="color: #942193;"&gt;"s/^(.*?)_(.*)$/\2/o"&lt;/SPAN&gt;,-&lt;SPAN style="color: #009193;"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/SPAN&gt;,crv);&lt;/P&gt;
&lt;P style="font-size: 14px; font-family: 'Courier New'; color: #011993;"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;SPAN style="color: #000000;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'll explain the regular expression:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;s = "substitute"&lt;/P&gt;&lt;P&gt;/ / / = delimiter for "from", "to"&lt;/P&gt;&lt;P&gt;^ = beginning of text&lt;/P&gt;&lt;P&gt;( ) = capture buffer, numbered in order.&amp;nbsp; So, there are two capture buffers.&lt;/P&gt;&lt;P&gt;. = any character&lt;/P&gt;&lt;P&gt;* = zero or more occurrences.&lt;/P&gt;&lt;P&gt;$ = end of text.&amp;nbsp; Note: the padding of SAS variables with spaces are significant.&amp;nbsp; With a different regular expression, you might need "trim(crv)"&lt;/P&gt;&lt;P&gt;\1 = the text captured in the first capture buffer&lt;/P&gt;&lt;P&gt;o = compile the regular expression once, and retain the regex across data step iterations.&amp;nbsp; Irrelevant in this example, but often used to increase performance.&lt;/P&gt;&lt;P&gt;-1 = apply the substitution to all occurrences of the regular expression in the source text (doesn't apply to this regex, since it encompasses the entire string).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ok, so in words, the first regular expression says "from the beginning of the text, find all characters ***, an underscore, then all characters until the end of the text, and substitute the text captured in the first capture buffer".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*** A key concept here is "greedy" vs. "non-greedy" matching (Google "regular expressions greedy matching").&amp;nbsp; By default, the matching is "greedy".&amp;nbsp; So, (.*) matches as many occurrences as it can, while still satisfying the rest of the regular expression _(.*)$&amp;nbsp; (underscore, any characters, end of line).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In the second regular expression, the ? metacharacter means "non-greedy" matching.&amp;nbsp; So, (.*?) means match the minimum occurrences, while still satisfying the rest of the regular expression (which is a "greedy" match).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've saved the results of capture buffer #2 so you can see the results of the greedy vs. non-greedy matching.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Uncomment the second crv setting so show that crv will be returned unchanged if it doesn't match the regular expression.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hope this helps,&lt;/P&gt;&lt;P&gt;Scott&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 30 Mar 2013 23:45:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93105#M19641</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2013-03-30T23:45:15Z</dc:date>
    </item>
    <item>
      <title>Re: how do I trim the piece to the right of the last underscore?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93106#M19642</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;P.S.:&amp;nbsp; I've just read PGStats' solution more closely, and mine isn't that much different than PGStats' solution.&amp;nbsp; Use whichever one works for you.&amp;nbsp; But do wrap your head around "greedy" vs. "non-greedy" - it applies to both solutions.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 31 Mar 2013 00:01:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93106#M19642</guid>
      <dc:creator>ScottBass</dc:creator>
      <dc:date>2013-03-31T00:01:31Z</dc:date>
    </item>
    <item>
      <title>Re: how do I trim the piece to the right of the last underscore?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93107#M19643</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you just want to replace a substring with a NULL string then why not formulate the RegEx accordingly?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;&amp;nbsp; infile datalines truncover;&lt;BR /&gt;&amp;nbsp; input in_string:$30.;&lt;BR /&gt;&amp;nbsp; length out_string $30.;&lt;BR /&gt;&amp;nbsp; out_string=prxchange('s/_+[^_]*$//o',1,in_string);&lt;BR /&gt;&amp;nbsp; datalines;&lt;BR /&gt;IR_MX_GOVT_BFV_MXN_7Y&lt;BR /&gt;IR_MX_GOVT_BFV_MXN____7Y&lt;BR /&gt;IRMXGOVTBFVMXN7Y&lt;BR /&gt;IR_MX_GOVTBFVMXN_7Y&lt;BR /&gt;IR_MX_GOVTBFVMXN_&lt;BR /&gt;;&amp;nbsp; &lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 31 Mar 2013 05:20:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93107#M19643</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2013-03-31T05:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: how do I trim the piece to the right of the last underscore?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93108#M19644</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There was never a mention of what to assign when there is no underscore in the string.&amp;nbsp; That's your assumption.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 31 Mar 2013 13:57:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93108#M19644</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2013-03-31T13:57:49Z</dc:date>
    </item>
    <item>
      <title>Re: how do I trim the piece to the right of the last underscore?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93109#M19645</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Because it uses a change (substitute) command when the pattern is not matched nothing is changed.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 31 Mar 2013 14:20:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93109#M19645</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-03-31T14:20:39Z</dc:date>
    </item>
    <item>
      <title>Re: how do I trim the piece to the right of the last underscore?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93110#M19646</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Indeed, my assumption was : no underscore -&amp;gt; nothing to trim. - PG&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 31 Mar 2013 14:27:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-trim-the-piece-to-the-right-of-the-last-underscore/m-p/93110#M19646</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2013-03-31T14:27:32Z</dc:date>
    </item>
  </channel>
</rss>

