<?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 multiple '_' and number in the string? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-multiple-and-number-in-the-string/m-p/369444#M88201</link>
    <description>&lt;P&gt;Hello:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following data.&amp;nbsp; I would like to remove all of the '_' and assign&amp;nbsp;what the&amp;nbsp;number in the string at the end.&amp;nbsp; Please help.&amp;nbsp; Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; Names&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;$100.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;cards&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;lab_den_pcr_perf_1&lt;/P&gt;
&lt;P&gt;mhh_cyto_tests_1__cfdna&lt;/P&gt;
&lt;P&gt;nad_cert_30&lt;/P&gt;
&lt;P&gt;nad_imag_find2___abn_cort_gyr&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;The result I am looking for is &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;labdenpcrperf1&lt;/P&gt;
&lt;P&gt;mhhcytotestscfdna1&lt;/P&gt;
&lt;P&gt;nadcert30&lt;/P&gt;
&lt;P&gt;nadimagfindabncortgyr2&lt;/P&gt;</description>
    <pubDate>Thu, 22 Jun 2017 14:09:13 GMT</pubDate>
    <dc:creator>ybz12003</dc:creator>
    <dc:date>2017-06-22T14:09:13Z</dc:date>
    <item>
      <title>How to remove multiple '_' and number in the string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-multiple-and-number-in-the-string/m-p/369444#M88201</link>
      <description>&lt;P&gt;Hello:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following data.&amp;nbsp; I would like to remove all of the '_' and assign&amp;nbsp;what the&amp;nbsp;number in the string at the end.&amp;nbsp; Please help.&amp;nbsp; Thanks.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; have;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; Names&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;$100.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;cards&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;lab_den_pcr_perf_1&lt;/P&gt;
&lt;P&gt;mhh_cyto_tests_1__cfdna&lt;/P&gt;
&lt;P&gt;nad_cert_30&lt;/P&gt;
&lt;P&gt;nad_imag_find2___abn_cort_gyr&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;The result I am looking for is &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;labdenpcrperf1&lt;/P&gt;
&lt;P&gt;mhhcytotestscfdna1&lt;/P&gt;
&lt;P&gt;nadcert30&lt;/P&gt;
&lt;P&gt;nadimagfindabncortgyr2&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 14:09:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-multiple-and-number-in-the-string/m-p/369444#M88201</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2017-06-22T14:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove multipul '_' and number in the string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-multiple-and-number-in-the-string/m-p/369450#M88203</link>
      <description>&lt;P&gt;You can use the COMPRESS function to remove certain characters from a string. Not sure what you mean by "assign&amp;nbsp;what the&amp;nbsp;number in the string at the end". Do you want to have the number of occurences of "_" at the end of each string?&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 12:13:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-multiple-and-number-in-the-string/m-p/369450#M88203</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-06-22T12:13:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove multipul '_' and number in the string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-multiple-and-number-in-the-string/m-p/369453#M88204</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Providing a "desired result" would help us to better understand what you're after.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The following code will populate a numeric variable with a number if digits only are found as the last element of your source string (with underscore separating the "elements").&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input Names :$100.;
  cards;
lab_den_pcr_perf_1
mhh_cyto_tests_1__cfdna
nad_cert_30
nad_imag_find2___abn_cort_gyr
;
run;

data want;
  set have;
  no_at_end_of_str=input(scan(names,-1,'_'),?? best32.);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Jun 2017 12:24:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-multiple-and-number-in-the-string/m-p/369453#M88204</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-06-22T12:24:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove multipul '_' and number in the string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-multiple-and-number-in-the-string/m-p/369459#M88206</link>
      <description>&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  names=cats(compress(names,"_","ka"),compress(names,"_","kd"));
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Jun 2017 12:55:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-multiple-and-number-in-the-string/m-p/369459#M88206</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-22T12:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove multipul '_' and number in the string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-multiple-and-number-in-the-string/m-p/369462#M88208</link>
      <description>&lt;P&gt;Here's a way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;prefix = compress(names, '_0123456789');&lt;/P&gt;
&lt;P&gt;suffix = compress(names, , 'kd' );&lt;/P&gt;
&lt;P&gt;names = strip(prefix) || suffix;&lt;/P&gt;
&lt;P&gt;drop prefix suffix;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One caution:&amp;nbsp; If there are multiple sets of digits, all of them get combined and put at the end.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;abc1_xyz2_def becomes abcxyzdef12&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 13:14:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-multiple-and-number-in-the-string/m-p/369462#M88208</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-06-22T13:14:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove multipul '_' and number in the string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-multiple-and-number-in-the-string/m-p/369463#M88209</link>
      <description>&lt;P&gt;Like this ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; want;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; have;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;n_position= anydigit(names,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;number= compress(substr(names,n_position),,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;"kd"&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;names_want= cats(compress(names,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'_'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;"d"&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;),number);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;keep&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; names_want;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Jun 2017 13:21:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-multiple-and-number-in-the-string/m-p/369463#M88209</guid>
      <dc:creator>DoumbiaS</dc:creator>
      <dc:date>2017-06-22T13:21:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove multipul '_' and number in the string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-multiple-and-number-in-the-string/m-p/369464#M88210</link>
      <description>&lt;P&gt;something like this in regex&lt;/P&gt;
&lt;PRE&gt;data want;
set have;
name = prxchange('s/_|([^\d]+$)//', -1, names);
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Jun 2017 13:24:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-multiple-and-number-in-the-string/m-p/369464#M88210</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2017-06-22T13:24:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove multipul '_' and number in the string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-multiple-and-number-in-the-string/m-p/369580#M88260</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Specifying the k-modifier in the compress function keeps the "_" instead of removing it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also think he wants the numbers at the end of the string instead of the beginning.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So modifying your code, I think this will work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want2;
  set have;
  names=cats(compress(names,"_","d"), compress(names,"_","a"));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Jun 2017 16:20:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-multiple-and-number-in-the-string/m-p/369580#M88260</guid>
      <dc:creator>jdwaterman91</dc:creator>
      <dc:date>2017-06-22T16:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove multipul '_' and number in the string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-multiple-and-number-in-the-string/m-p/369582#M88262</link>
      <description>&lt;P&gt;Actually my code is fine, just remove the _, whiich I added in haste:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  names=cats(compress(names,"","ka"),compress(names,"","kd"));
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Jun 2017 16:25:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-multiple-and-number-in-the-string/m-p/369582#M88262</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-22T16:25:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove multipul '_' and number in the string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-multiple-and-number-in-the-string/m-p/370100#M88395</link>
      <description>&lt;P&gt;I start to understand what the prxchange means.&lt;/P&gt;</description>
      <pubDate>Fri, 23 Jun 2017 19:14:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-multiple-and-number-in-the-string/m-p/370100#M88395</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2017-06-23T19:14:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to remove multiple '_' and number in the string?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-remove-multiple-and-number-in-the-string/m-p/370226#M88426</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/67134"&gt;@ybz12003&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The following code returns the desired output as you've posted.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Based on your narrative I'm not sure if this really is what you're after. If not then please post some additional sample data where it's not working for you.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input Names :$100.;
  cards;
lab_den_pcr_perf_1
mhh_cyto_tests_1__cfdna
nad_cert_30
nad_imag_find2___abn_cort_gyr
;
run;

data want;
  set have;
  length names_want $100;
  names_want=cats(compress(Names,'_','d'),compress(Names,,'kd'));
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 24 Jun 2017 05:49:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-remove-multiple-and-number-in-the-string/m-p/370226#M88426</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-06-24T05:49:34Z</dc:date>
    </item>
  </channel>
</rss>

