<?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 a Character at the end of the string Based on Criteria in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-Character-at-the-end-of-the-string-Based-on/m-p/904905#M357468</link>
    <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;If the variable contains only 'numeric' and '-' in text, then delete '-' at the end; otherwise, keep it. Please let me know if I missed any scenario&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is how I would program this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    if anyalpha(reason)=0 /* No alphabetical characters */ 
        /* does it contain - */ and find(reason,'-')&amp;gt;0 
        /* Is last character - */ and reverse(trim(reason))=:'-'
        then /* Remove - at end */ reason=substr(reason,1,length(reason)-1);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 28 Nov 2023 16:09:51 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-11-28T16:09:51Z</dc:date>
    <item>
      <title>How to remove a Character at the end of the string Based on Criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-Character-at-the-end-of-the-string-Based-on/m-p/904871#M357462</link>
      <description>&lt;P&gt;I have the following scenario where I need to remove the '-' from the end of the string.&lt;/P&gt;
&lt;P&gt;1. If the 'reason' (VARIABLE) is total text, then KEEP '-' at the end of the string.&lt;/P&gt;
&lt;P&gt;2. If the 'reason' (VARIABLE) is a partial date with '-' at the end, then delete the '-' at the end of the string.&lt;/P&gt;
&lt;P&gt;3. If the 'reason' (VARIABLE) is complete date&amp;nbsp; without '-' at the end keep the text as it is.&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF00FF"&gt;&lt;STRONG&gt;Have data:&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASuserlot_0-1701184037844.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/90316iBC806224355269AC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASuserlot_0-1701184037844.png" alt="SASuserlot_0-1701184037844.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#008000"&gt;Want:&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#008000"&gt;1.&amp;nbsp; didnot go to store&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#008000"&gt;2.&amp;nbsp; 2017-20&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#008000"&gt;3. 2017-21-01&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Thank you for your suggestions and time&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 reason = 'didnot go to store-';
 output;
 reason = '2017-20-';
 output;
 reason = '2017-21-01';
 output;
 run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2023 15:08:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-Character-at-the-end-of-the-string-Based-on/m-p/904871#M357462</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2023-11-28T15:08:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove a Character at the end of the string Based on Criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-Character-at-the-end-of-the-string-Based-on/m-p/904872#M357463</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/350312"&gt;@SASuserlot&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. If the 'reason' (VARIABLE) is total text, then KEEP '-' at the end of the string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#008000"&gt;Want:&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#008000"&gt;1.&amp;nbsp; didnot go to store&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;These two are contradictory. Which do you want, keep the '-' at the end of the string, or remove as you indicate in&amp;nbsp; "Want"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, what counts as a partial date? Is 01JAN- a partial date? What should we do about text like 'purchase $12.79' which isn't what you describe as 'total text', and is not a date or partial date?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2023 15:33:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-Character-at-the-end-of-the-string-Based-on/m-p/904872#M357463</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-11-28T15:33:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove a Character at the end of the string Based on Criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-Character-at-the-end-of-the-string-Based-on/m-p/904889#M357466</link>
      <description>&lt;P&gt;Thank you for your questions.&lt;/P&gt;
&lt;P&gt;That's the tricky part of the data at this moment I have.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the text contains 'Alphabetical characters'. then Keep '-'.&lt;/P&gt;
&lt;P&gt;If the text contains only dates in the character string ( contains ONLY numerical and '-').&amp;nbsp; If any character date didn't have the year, month, and date (2018-01-, 2018-), it was considered a partial date. Also, your example is regarded as a partial date. For the time being, it's mandatory to have the 'Year' in my data.&lt;/P&gt;
&lt;P&gt;Your case "&lt;SPAN&gt;&amp;nbsp;'purchase $12.79" we keep '-'.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;To make it easier to understand. If the variable contains only 'numeric' and '-' in text, then delete '-' at the end; otherwise, keep it. Please let me know if I missed any scenario&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2023 15:56:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-Character-at-the-end-of-the-string-Based-on/m-p/904889#M357466</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2023-11-28T15:56:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove a Character at the end of the string Based on Criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-Character-at-the-end-of-the-string-Based-on/m-p/904903#M357467</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 reason = 'didnot go to store-';
 output;
 reason = '2017-20-';
 output;
 reason = '2017-21-01';
 output;
 reason= '17-NOV-';
 output;

data want;
 	set have;
	if substr(reason, length(reason), 1)= '-' then do;
		if anyalpha(reason) eq 0 then reason=substr(reason, 1, length(reason)-1);
	end; 
proc print;run;  &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Does this work the way you want?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2023 16:06:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-Character-at-the-end-of-the-string-Based-on/m-p/904903#M357467</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2023-11-28T16:06:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove a Character at the end of the string Based on Criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-Character-at-the-end-of-the-string-Based-on/m-p/904905#M357468</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;If the variable contains only 'numeric' and '-' in text, then delete '-' at the end; otherwise, keep it. Please let me know if I missed any scenario&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is how I would program this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set have;
    if anyalpha(reason)=0 /* No alphabetical characters */ 
        /* does it contain - */ and find(reason,'-')&amp;gt;0 
        /* Is last character - */ and reverse(trim(reason))=:'-'
        then /* Remove - at end */ reason=substr(reason,1,length(reason)-1);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Nov 2023 16:09:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-Character-at-the-end-of-the-string-Based-on/m-p/904905#M357468</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-11-28T16:09:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove a Character at the end of the string Based on Criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-Character-at-the-end-of-the-string-Based-on/m-p/904908#M357470</link>
      <description>&lt;P&gt;Thank you for quick solution. your code and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; code both worked great. Thank you both.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2023 16:12:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-Character-at-the-end-of-the-string-Based-on/m-p/904908#M357470</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2023-11-28T16:12:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove a Character at the end of the string Based on Criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-Character-at-the-end-of-the-string-Based-on/m-p/904909#M357471</link>
      <description>&lt;P&gt;It Worked. THANK YOU...&lt;/P&gt;</description>
      <pubDate>Tue, 28 Nov 2023 16:12:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-Character-at-the-end-of-the-string-Based-on/m-p/904909#M357471</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2023-11-28T16:12:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove a Character at the end of the string Based on Criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-Character-at-the-end-of-the-string-Based-on/m-p/905087#M357501</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
 reason = 'didnot go to store-';
 output;
 reason = '2017-20-';
 output;
 reason = '2017-21-01';
 output;
 run;
data want;
 set have;
 want=prxchange('s/(\d)\-+$/\1/',1,strip(reason));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Nov 2023 05:45:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-Character-at-the-end-of-the-string-Based-on/m-p/905087#M357501</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-11-29T05:45:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove a Character at the end of the string Based on Criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-Character-at-the-end-of-the-string-Based-on/m-p/906042#M357806</link>
      <description>&lt;P&gt;thank you&lt;/P&gt;</description>
      <pubDate>Mon, 04 Dec 2023 15:47:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-a-Character-at-the-end-of-the-string-Based-on/m-p/906042#M357806</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2023-12-04T15:47:04Z</dc:date>
    </item>
  </channel>
</rss>

