<?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 How to remove last character in the string if it is a '+' in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-last-character-in-the-string-if-it-is-a/m-p/408463#M99726</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a variable 'name' like this -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input name $30. ;&lt;BR /&gt;datalines;&lt;BR /&gt;aaaaa+&lt;BR /&gt;bbb+aa+&lt;BR /&gt;dd+cc&lt;BR /&gt;fff+aa+dd+&lt;BR /&gt;gg+d&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need the last character in the string to be removed only if it is a '+'. Some observations don't end in a '+' and those should be left as is. Also the '+' in other positions in the variable should be left as is, only if it is in the last position, it needs to be remove. How do I do this? Any advice is appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is how I want it to look:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Name&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;aaaaa&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;bbb+aa&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dd+cc&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fff+aa+dd&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gg+d&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 30 Oct 2017 04:29:41 GMT</pubDate>
    <dc:creator>ahhh</dc:creator>
    <dc:date>2017-10-30T04:29:41Z</dc:date>
    <item>
      <title>How to remove last character in the string if it is a '+'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-last-character-in-the-string-if-it-is-a/m-p/408463#M99726</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a variable 'name' like this -&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input name $30. ;&lt;BR /&gt;datalines;&lt;BR /&gt;aaaaa+&lt;BR /&gt;bbb+aa+&lt;BR /&gt;dd+cc&lt;BR /&gt;fff+aa+dd+&lt;BR /&gt;gg+d&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need the last character in the string to be removed only if it is a '+'. Some observations don't end in a '+' and those should be left as is. Also the '+' in other positions in the variable should be left as is, only if it is in the last position, it needs to be remove. How do I do this? Any advice is appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is how I want it to look:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Name&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;aaaaa&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;bbb+aa&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dd+cc&amp;nbsp;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fff+aa+dd&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gg+d&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2017 04:29:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-last-character-in-the-string-if-it-is-a/m-p/408463#M99726</guid>
      <dc:creator>ahhh</dc:creator>
      <dc:date>2017-10-30T04:29:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove last character in the string if it is a '+'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-last-character-in-the-string-if-it-is-a/m-p/408466#M99728</link>
      <description>&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input name $30. ;&lt;BR /&gt;a=compress(name,' ','ka');&lt;BR /&gt;datalines;&lt;BR /&gt;aaaaa+&lt;BR /&gt;bbb+aa+&lt;BR /&gt;dd+cc&lt;BR /&gt;fff+aa+dd+&lt;BR /&gt;gg+d&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;by using compress function with keep only alphabetics we can remove '+' from the given data&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2017 04:46:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-last-character-in-the-string-if-it-is-a/m-p/408466#M99728</guid>
      <dc:creator>rajeshalwayswel</dc:creator>
      <dc:date>2017-10-30T04:46:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove last character in the string if it is a '+'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-last-character-in-the-string-if-it-is-a/m-p/408469#M99731</link>
      <description>Thanks! But, I would still like to keep the '+' in the middle. Only if the string ends with a '+' , only that '+' needs to be removed. Other '+'s should be left as is...</description>
      <pubDate>Mon, 30 Oct 2017 04:55:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-last-character-in-the-string-if-it-is-a/m-p/408469#M99731</guid>
      <dc:creator>ahhh</dc:creator>
      <dc:date>2017-10-30T04:55:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove last character in the string if it is a '+'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-last-character-in-the-string-if-it-is-a/m-p/408475#M99732</link>
      <description>&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input name $30. ;&lt;BR /&gt;if substr(reverse(strip(name)),1,1)='+' then a=reverse(substr(reverse(strip(name)),2));&lt;BR /&gt;else a=name;&lt;BR /&gt;datalines;&lt;BR /&gt;aaaaa+&lt;BR /&gt;bbb+aa+&lt;BR /&gt;dd+cc&lt;BR /&gt;fff+aa+dd+&lt;BR /&gt;gg+d&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2017 05:07:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-last-character-in-the-string-if-it-is-a/m-p/408475#M99732</guid>
      <dc:creator>rajeshalwayswel</dc:creator>
      <dc:date>2017-10-30T05:07:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove last character in the string if it is a '+'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-last-character-in-the-string-if-it-is-a/m-p/408499#M99742</link>
      <description>&lt;P&gt;Alternative:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
if substr(name,length(name),1) = '+' then name = substr(name,1,length(name)-1);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Oct 2017 07:04:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-last-character-in-the-string-if-it-is-a/m-p/408499#M99742</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-10-30T07:04:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove last character in the string if it is a '+'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-last-character-in-the-string-if-it-is-a/m-p/408634#M99783</link>
      <description>&lt;PRE&gt;

data have;
input name $30. ;
want=prxchange('s/\++$//',1,strip(name));
datalines;
aaaaa+
bbb+aa+
dd+cc
fff+aa+dd+
gg+d
;
run;

&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Oct 2017 12:58:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-last-character-in-the-string-if-it-is-a/m-p/408634#M99783</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-10-30T12:58:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove last character in the string if it is a '+'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-last-character-in-the-string-if-it-is-a/m-p/408741#M99820</link>
      <description>Thank you!</description>
      <pubDate>Mon, 30 Oct 2017 15:26:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-last-character-in-the-string-if-it-is-a/m-p/408741#M99820</guid>
      <dc:creator>ahhh</dc:creator>
      <dc:date>2017-10-30T15:26:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove last character in the string if it is a '+'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-last-character-in-the-string-if-it-is-a/m-p/408743#M99822</link>
      <description>Thank you!&lt;BR /&gt;</description>
      <pubDate>Mon, 30 Oct 2017 15:27:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-last-character-in-the-string-if-it-is-a/m-p/408743#M99822</guid>
      <dc:creator>ahhh</dc:creator>
      <dc:date>2017-10-30T15:27:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove last character in the string if it is a '+'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-last-character-in-the-string-if-it-is-a/m-p/408745#M99823</link>
      <description>&lt;P&gt;Thanks everyone! it worked!&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2017 15:27:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-last-character-in-the-string-if-it-is-a/m-p/408745#M99823</guid>
      <dc:creator>ahhh</dc:creator>
      <dc:date>2017-10-30T15:27:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove last character in the string if it is a '+'</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-last-character-in-the-string-if-it-is-a/m-p/408910#M99865</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm wondering how it works can you please explain&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;prxchange function.&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Thanks,&lt;/P&gt;&lt;P&gt;Rajesh&lt;/P&gt;</description>
      <pubDate>Mon, 30 Oct 2017 21:06:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-last-character-in-the-string-if-it-is-a/m-p/408910#M99865</guid>
      <dc:creator>rajeshalwayswel</dc:creator>
      <dc:date>2017-10-30T21:06:10Z</dc:date>
    </item>
  </channel>
</rss>

