<?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: function for stripping leading and trailing characters other than blanks? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/function-for-stripping-leading-and-trailing-characters-other/m-p/322543#M71363</link>
    <description>&lt;P&gt;You may need to provide examples of what you want if they are more complex. Are the values you are considering embedded inside a longer string? Do they occur at something that may be considered a "word boundary"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may consider looking into Proc&amp;nbsp;FCMP if you want to move a bunch of possibly routine, tedious, long and ugly string functions out of the data step you that you can do something like: newvar = MySpecialString(oldvar); as a single call in the data step.&lt;/P&gt;
&lt;P&gt;That way the function does what you need and not what someone else thinks you need.&lt;/P&gt;</description>
    <pubDate>Wed, 04 Jan 2017 23:40:11 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2017-01-04T23:40:11Z</dc:date>
    <item>
      <title>function for stripping leading and trailing characters other than blanks?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/function-for-stripping-leading-and-trailing-characters-other/m-p/322494#M71347</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I googled this topic and found a 2012 issue just like it where someone suggested adding a new function like this to the SAS Ballet. &amp;nbsp;Since it's about 5 years later, I'm wondering if it made it to the ballet (if not, I'll put it there)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to specify a particular character that I want stripped from beginning, end, or both of a character string field.&lt;/P&gt;
&lt;P&gt;For example, I would like any records with a character value ending in a comma to have the comma stripped.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know how to do it the long way, but it seems like a common enough need that a new function might be helpful to more folks than me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks so much, and sorry if it's out there already and I just missed it! &amp;nbsp;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Barb&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 21:00:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/function-for-stripping-leading-and-trailing-characters-other/m-p/322494#M71347</guid>
      <dc:creator>BRKS</dc:creator>
      <dc:date>2017-01-04T21:00:36Z</dc:date>
    </item>
    <item>
      <title>Re: function for stripping leading and trailing characters other than blanks?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/function-for-stripping-leading-and-trailing-characters-other/m-p/322506#M71349</link>
      <description>&lt;P&gt;As long as there are no commas in the interior of the string, then you could use the SCAN function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;509  data x;
510    a=',,,word,,,';
511
512    w=scan(a,1,',');
513    put a= w=;
514  run;

a=,,,word,,, w=word
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not exactly a STRIP function, but possibly close enough.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 21:40:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/function-for-stripping-leading-and-trailing-characters-other/m-p/322506#M71349</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-01-04T21:40:23Z</dc:date>
    </item>
    <item>
      <title>Re: function for stripping leading and trailing characters other than blanks?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/function-for-stripping-leading-and-trailing-characters-other/m-p/322543#M71363</link>
      <description>&lt;P&gt;You may need to provide examples of what you want if they are more complex. Are the values you are considering embedded inside a longer string? Do they occur at something that may be considered a "word boundary"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may consider looking into Proc&amp;nbsp;FCMP if you want to move a bunch of possibly routine, tedious, long and ugly string functions out of the data step you that you can do something like: newvar = MySpecialString(oldvar); as a single call in the data step.&lt;/P&gt;
&lt;P&gt;That way the function does what you need and not what someone else thinks you need.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Jan 2017 23:40:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/function-for-stripping-leading-and-trailing-characters-other/m-p/322543#M71363</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-01-04T23:40:11Z</dc:date>
    </item>
    <item>
      <title>Re: function for stripping leading and trailing characters other than blanks?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/function-for-stripping-leading-and-trailing-characters-other/m-p/322561#M71371</link>
      <description>&lt;P&gt;Regular expressions do this easily.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here, we remove any starting or ending comma or space; that's what the&lt;FONT face="courier new,courier"&gt; (,| )&lt;/FONT&gt; group defines: comma or space.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  STR1=',,aaaaa,aa, , ';
  STR2=prxchange('s/^(,| )*(.*?)(,| )*$/$2/o',1,STR1);
  putlog STR2= ;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;STR2=aaaaa,aa&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This expression reads as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1- match any number of spaces and commas right after the beginning of the string&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ^(,| )*&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2- then match what ever else can be matched (but as little as possible in order maximize 1 and 3)&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (.*?)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3- then match any number of spaces and commas right to the end of the string&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (,| )*$&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4- only keep 2-&amp;nbsp;&amp;nbsp; (i.e. discard starting and ending commas and spaces)&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $2&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jan 2017 02:28:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/function-for-stripping-leading-and-trailing-characters-other/m-p/322561#M71371</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-01-05T02:28:59Z</dc:date>
    </item>
    <item>
      <title>Re: function for stripping leading and trailing characters other than blanks?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/function-for-stripping-leading-and-trailing-characters-other/m-p/322565#M71373</link>
      <description>&lt;P&gt;You can even create the list of matched characters separately.&lt;/P&gt;
&lt;P&gt;Here is a variation on the same theme:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let list=%str(, );
data _null_;
  STR1=', ,,aaaaa,aa, , ';
  STR2=prxchange("s/^[&amp;amp;list]*(.*?)[&amp;amp;list]*$/$1/o",1,STR1);
  putlog STR2= ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So you can easily create a macro or an fcmp function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro stripchars(var,chars);
   prxchange("s/^[&amp;amp;chars]*(.*?)[&amp;amp;chars]*$/$1/o",1,&amp;amp;var.)
%mend;

data _null_;
  STR1=', ,,aaaa,aaa, , ';
  STR1=%stripchars(STR1,%str(, ));
  putlog STR1= ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jan 2017 02:39:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/function-for-stripping-leading-and-trailing-characters-other/m-p/322565#M71373</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-01-05T02:39:45Z</dc:date>
    </item>
    <item>
      <title>Re: function for stripping leading and trailing characters other than blanks?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/function-for-stripping-leading-and-trailing-characters-other/m-p/322666#M71403</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks for your assistance! &amp;nbsp;Looks like there is not a function.&lt;/P&gt;
&lt;P&gt;I'm all set and know how to work around this, and don't need any further help.&lt;/P&gt;
&lt;P&gt;I was just wondering if there was a function to strip a specified charracter at the end of a string.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Barb&lt;/P&gt;</description>
      <pubDate>Thu, 05 Jan 2017 14:30:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/function-for-stripping-leading-and-trailing-characters-other/m-p/322666#M71403</guid>
      <dc:creator>BRKS</dc:creator>
      <dc:date>2017-01-05T14:30:45Z</dc:date>
    </item>
  </channel>
</rss>

