<?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: deleting substrings from a string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/deleting-substrings-from-a-string/m-p/640626#M190874</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;: you are absolutely right about storing the strings to search for in a dataset, but i can't recommend stored data in macro-variables, because this can cause errors as soon as the list gets longer.Using point-option two dataset can be combined:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set art2;
    
    length abbrev_codes2 $ 100 i 8;
    drop i;
    
    abbrev_codes2 = abbrev_codes;
    
    do i = 1 to num_terms;
        set list_terms point=i nobs=num_terms;
        abbrev_codes2 = tranwrd(abbrev_codes2, trim(terms), "");
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 17 Apr 2020 07:40:23 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2020-04-17T07:40:23Z</dc:date>
    <item>
      <title>deleting substrings from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-substrings-from-a-string/m-p/640598#M190853</link>
      <description>&lt;P&gt;Hi friends;&lt;/P&gt;&lt;P&gt;I am asking for help from a someone out there! I am new to SAS. I would like to delete multiple substrings from a string variable. I am using the tranwrd statement.I am not sure why the code is not eliminating substrings specified. Anyone willing to scanm through my code? Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA art2;&lt;BR /&gt;SET art2;&lt;BR /&gt;do list="hxu","Hydroxyure","ntiretroviralTreatmentotSpecified","Antiretroviral",&lt;BR /&gt;"and","Antiretroviral Treatment Not cified","iretroviral Treatment Not Specified",&lt;BR /&gt;"Ant troviral Treatment Not Specified";&lt;BR /&gt;abbrev_codes2=tranwrd(abbrev_codes, list,"");&lt;BR /&gt;end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data i have and the one i want is given below;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;iretroviral Treatment Not Specified, L667&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;apv, ddi, d4t, abc, hxu&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;iretroviral Treatment Not Specified, lov&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;apv, ddi, d4t, abc, hxu,Hydroxyure&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;apv, ddi, d4t, abc, iretroviral Treatment Not Specified&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data I want&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;L667&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;apv, ddi, d4t, abc&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;lov&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;apv, ddi, d4t, abc&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;apv, ddi, d4t, abc&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for your helpl;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dathan Byonanebye&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 02:35:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-substrings-from-a-string/m-p/640598#M190853</guid>
      <dc:creator>DathanMD</dc:creator>
      <dc:date>2020-04-17T02:35:04Z</dc:date>
    </item>
    <item>
      <title>Re: deleting substrings from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-substrings-from-a-string/m-p/640601#M190856</link>
      <description>&lt;P&gt;You need to apply each deletion to the result of the previous deletion:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA art3;
SET art2;
abbrev_codes2 = abbrev_codes;
do list="hxu","Hydroxyure","ntiretroviralTreatmentotSpecified","Antiretroviral",
"and","Antiretroviral Treatment Not cified","iretroviral Treatment Not Specified",
"Ant troviral Treatment Not Specified";
abbrev_codes2=tranwrd(abbrev_codes2, list, "");
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You may also want to remove the commas.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 02:50:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-substrings-from-a-string/m-p/640601#M190856</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-04-17T02:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: deleting substrings from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-substrings-from-a-string/m-p/640613#M190866</link>
      <description>&lt;P&gt;Some things to note:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;never overwrite the dataset you are processing&lt;/LI&gt;
&lt;LI&gt;add a length-statement for all variable you are using, that are not read from a dataset&lt;/LI&gt;
&lt;LI&gt;use put-statement to debug your code, adding &lt;FONT face="courier new,courier"&gt;put abbrev_codes= abbrev_codes2=;&lt;/FONT&gt; before the end of the loop shows what is happening.&lt;/LI&gt;
&lt;/UL&gt;</description>
      <pubDate>Fri, 17 Apr 2020 05:50:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-substrings-from-a-string/m-p/640613#M190866</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-04-17T05:50:21Z</dc:date>
    </item>
    <item>
      <title>Re: deleting substrings from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-substrings-from-a-string/m-p/640618#M190868</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/294150"&gt;@DathanMD&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an approach to achieve this.&lt;/P&gt;
&lt;P&gt;I recommend that you use a dataset to store the list of terms to identify rather than putting them directly in the code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data art2;
	infile datalines dlm="09"x;
	input abbrev_codes :$100.;
	datalines;
iretroviral Treatment Not Specified, L667
apv, ddi, d4t, abc, hxu
iretroviral Treatment Not Specified, lov
apv, ddi, d4t, abc, hxu,Hydroxyure
apv, ddi, d4t, abc, iretroviral Treatment Not Specified
;
run;

/* Put reference terms to look for into a dataset -&amp;gt; easier to maintain */

data list_terms;
	infile datalines dlm="09"x;
	input terms :$100.;
	datalines;
hxu
Hydroxyure
ntiretroviralTreatmentotSpecified
Antiretroviral
and
Antiretroviral Treatment Not cified
iretroviral Treatment Not Specified
Ant troviral Treatment Not Specified
;
run;

/* Define macrovariables*/

proc sql noprint;
	select max(countw(abbrev_codes,",")) into:nb_codes from art2;
	select count(terms) into:nb_terms from list_terms;
	select quote(terms,"") into:list separated by "," from list_terms;
quit;

/* Look for the reference terms */

data art3;
	set art2;
	length abbrev_codes2 $100;
	array _abbrev_codes(&amp;amp;nb_codes.) $100;
	array _list(&amp;amp;nb_terms.) $100 _temporary_ (&amp;amp;list.);
	
	do i=1 to dim(_abbrev_codes);
	
		_abbrev_codes(i) = scan(abbrev_codes,i,",");
		
		do j=1 to dim(_list);
			if strip(_abbrev_codes(i)) = strip(_list(j)) then do;
				_abbrev_codes(i) = "";
				leave;
			end;
		end;

	if _abbrev_codes(i) ne "" then abbrev_codes2 = catx(",", abbrev_codes2,_abbrev_codes(i));
	end;
	
	drop i j _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture d’écran 2020-04-17 à 09.00.19.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/38361iB2D70DB53090BCBF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Capture d’écran 2020-04-17 à 09.00.19.png" alt="Capture d’écran 2020-04-17 à 09.00.19.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 07:03:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-substrings-from-a-string/m-p/640618#M190868</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-04-17T07:03:44Z</dc:date>
    </item>
    <item>
      <title>Re: deleting substrings from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-substrings-from-a-string/m-p/640625#M190873</link>
      <description>&lt;P&gt;[Edited to provide improved working code]&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data TERMS;
  infile cards pad ;
  input TERM &amp;amp; $100.;
  cards;
hxu
Hydroxyure
Antiretroviral
and
\w{1,4}roviral ?Treatment ?N?ot.{0,4}cified
run;

data HAVE;
  infile cards pad;
  input ABBREV_CODE &amp;amp; $100.;
  cards;
iretroviral Treatment Not Specified, L667
apv, ddi, d4t, abc, hxu
iretroviral Treatment Not Specified, lov
apv, ddi, d4t, abc, hxu,Hydroxyure
apv, ddi, d4t, abc, iretroviral Treatment Not Specified
run;

data WANT;
  length REGEX $32700;
  retain REGEX;
  drop   REGEX TERM;
  if _N_=1 then do until(LASTOBS);
    set TERMS end=LASTOBS; 
    REGEX=catx('|',REGEX,TERM);
  end;
  set HAVE;
  ABBREV_CODE2=prxchange(catt('s/,? ?(',REGEX,'),?//o'),-1,ABBREV_CODE);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;TABLE class="table" style="border-collapse: collapse; border-spacing: 0px; margin-bottom: 1em; border-width: 1px 0px 0px 1px; border-style: solid; border-color: #c1c1c1; border-image: initial; margin-left: auto; margin-right: auto; color: #000000; font-family: Arial, 'Albany AMT', Helvetica, Helv; font-size: x-small; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: center; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #fafbfe; text-decoration-style: initial; text-decoration-color: initial;" aria-label="Data Set WORK.WANT"&gt;&lt;CAPTION aria-label="Data Set WORK.WANT"&gt;&amp;nbsp;&lt;/CAPTION&gt;&lt;COLGROUP&gt;&lt;COL style="border-left: 1px solid #c1c1c1; border-right: 0px solid #c1c1c1;" /&gt;&lt;COL style="border-left: 1px solid #c1c1c1; border-right: 0px solid #c1c1c1;" /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR style="border-top: 1px solid #c1c1c1; border-bottom: 0px solid #c1c1c1;"&gt;
&lt;TH class="header" style="text-align: left; padding: 3px 6px; vertical-align: top; background-color: #edf2f9; border-color: #b0b7bb; border-style: solid; border-width: 0px 1px 1px 0px; color: #112277; font-family: Arial, 'Albany AMT', Helvetica, Helv; font-size: x-small; font-style: normal; font-weight: bold;" scope="col"&gt;ABBREV_CODE&lt;/TH&gt;
&lt;TH class="header" style="text-align: left; padding: 3px 6px; vertical-align: top; background-color: #edf2f9; border-color: #b0b7bb; border-style: solid; border-width: 0px 1px 1px 0px; color: #112277; font-family: Arial, 'Albany AMT', Helvetica, Helv; font-size: x-small; font-style: normal; font-weight: bold;" scope="col"&gt;ABBREV_CODE2&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR style="border-top: 1px solid #c1c1c1; border-bottom: 0px solid #c1c1c1;"&gt;
&lt;TD class="data" style="text-align: left; padding: 3px 6px; vertical-align: top; background-color: #ffffff; border-color: #c1c1c1; border-style: solid; border-width: 0px 1px 1px 0px; font-family: Arial, 'Albany AMT', Helvetica, Helv; font-size: x-small; font-style: normal; font-weight: normal;"&gt;iretroviral Treatment Not Specified, L667&lt;/TD&gt;
&lt;TD class="data" style="text-align: left; padding: 3px 6px; vertical-align: top; background-color: #ffffff; border-color: #c1c1c1; border-style: solid; border-width: 0px 1px 1px 0px; font-family: Arial, 'Albany AMT', Helvetica, Helv; font-size: x-small; font-style: normal; font-weight: normal;"&gt;L667&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="border-top: 1px solid #c1c1c1; border-bottom: 0px solid #c1c1c1;"&gt;
&lt;TD class="data" style="text-align: left; padding: 3px 6px; vertical-align: top; background-color: #ffffff; border-color: #c1c1c1; border-style: solid; border-width: 0px 1px 1px 0px; font-family: Arial, 'Albany AMT', Helvetica, Helv; font-size: x-small; font-style: normal; font-weight: normal;"&gt;apv, ddi, d4t, abc, hxu&lt;/TD&gt;
&lt;TD class="data" style="text-align: left; padding: 3px 6px; vertical-align: top; background-color: #ffffff; border-color: #c1c1c1; border-style: solid; border-width: 0px 1px 1px 0px; font-family: Arial, 'Albany AMT', Helvetica, Helv; font-size: x-small; font-style: normal; font-weight: normal;"&gt;apv, ddi, d4t, abc&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="border-top: 1px solid #c1c1c1; border-bottom: 0px solid #c1c1c1;"&gt;
&lt;TD class="data" style="text-align: left; padding: 3px 6px; vertical-align: top; background-color: #ffffff; border-color: #c1c1c1; border-style: solid; border-width: 0px 1px 1px 0px; font-family: Arial, 'Albany AMT', Helvetica, Helv; font-size: x-small; font-style: normal; font-weight: normal;"&gt;iretroviral Treatment Not Specified, lov&lt;/TD&gt;
&lt;TD class="data" style="text-align: left; padding: 3px 6px; vertical-align: top; background-color: #ffffff; border-color: #c1c1c1; border-style: solid; border-width: 0px 1px 1px 0px; font-family: Arial, 'Albany AMT', Helvetica, Helv; font-size: x-small; font-style: normal; font-weight: normal;"&gt;lov&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="border-top: 1px solid #c1c1c1; border-bottom: 0px solid #c1c1c1;"&gt;
&lt;TD class="data" style="text-align: left; padding: 3px 6px; vertical-align: top; background-color: #ffffff; border-color: #c1c1c1; border-style: solid; border-width: 0px 1px 1px 0px; font-family: Arial, 'Albany AMT', Helvetica, Helv; font-size: x-small; font-style: normal; font-weight: normal;"&gt;apv, ddi, d4t, abc, hxu,Hydroxyure&lt;/TD&gt;
&lt;TD class="data" style="text-align: left; padding: 3px 6px; vertical-align: top; background-color: #ffffff; border-color: #c1c1c1; border-style: solid; border-width: 0px 1px 1px 0px; font-family: Arial, 'Albany AMT', Helvetica, Helv; font-size: x-small; font-style: normal; font-weight: normal;"&gt;apv, ddi, d4t, abc&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="border-top: 1px solid #c1c1c1; border-bottom: 0px solid #c1c1c1;"&gt;
&lt;TD class="data" style="text-align: left; padding: 3px 6px; vertical-align: top; background-color: #ffffff; border-color: #c1c1c1; border-style: solid; border-width: 0px 1px 1px 0px; font-family: Arial, 'Albany AMT', Helvetica, Helv; font-size: x-small; font-style: normal; font-weight: normal;"&gt;apv, ddi, d4t, abc, iretroviral Treatment Not Specified&lt;/TD&gt;
&lt;TD class="data" style="text-align: left; padding: 3px 6px; vertical-align: top; background-color: #ffffff; border-color: #c1c1c1; border-style: solid; border-width: 0px 1px 1px 0px; font-family: Arial, 'Albany AMT', Helvetica, Helv; font-size: x-small; font-style: normal; font-weight: normal;"&gt;apv, ddi, d4t, abc&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&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>Fri, 17 Apr 2020 11:02:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-substrings-from-a-string/m-p/640625#M190873</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-04-17T11:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: deleting substrings from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-substrings-from-a-string/m-p/640626#M190874</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;: you are absolutely right about storing the strings to search for in a dataset, but i can't recommend stored data in macro-variables, because this can cause errors as soon as the list gets longer.Using point-option two dataset can be combined:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
    set art2;
    
    length abbrev_codes2 $ 100 i 8;
    drop i;
    
    abbrev_codes2 = abbrev_codes;
    
    do i = 1 to num_terms;
        set list_terms point=i nobs=num_terms;
        abbrev_codes2 = tranwrd(abbrev_codes2, trim(terms), "");
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Apr 2020 07:40:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-substrings-from-a-string/m-p/640626#M190874</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-04-17T07:40:23Z</dc:date>
    </item>
    <item>
      <title>Re: deleting substrings from a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/deleting-substrings-from-a-string/m-p/640646#M190882</link>
      <description>&lt;P&gt;It not worked because:&lt;/P&gt;
&lt;P&gt;1- add an output to debug&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA art2;
SET art2;
do list="hxu","Hydroxyure","ntiretroviralTreatmentotSpecified","Antiretroviral",
"and","Antiretroviral Treatment Not cified","iretroviral Treatment Not Specified",
"Ant troviral Treatment Not Specified";
abbrev_codes2=tranwrd(abbrev_codes, list,"");
output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2- you dont define length of list then &amp;gt;&amp;gt;&amp;gt; length(list) = length("hxu")=3&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; list = "hxu","Hyd", "nti" , …. "Ant"&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; need to define length of list&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt; don't forget&amp;nbsp;&lt;SPAN style="background-color: #ffffff; box-sizing: border-box; color: #333333; display: inline; float: none; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;abbrev_codes2&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;LENGTH&amp;nbsp;&lt;SPAN style="background-color: #ffffff; box-sizing: border-box; color: #333333; display: inline; float: none; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;abbrev_codes2&lt;/SPAN&gt; list $100&lt;/P&gt;
&lt;P&gt;3-&amp;nbsp;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;abbrev_codes2=tranwrd(abbrev_codes, list,""); &amp;nbsp; &amp;gt;&amp;gt;&amp;gt; this line of code&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;&amp;gt;&amp;gt;&amp;gt; resultat = replace only "Ant" in&amp;nbsp;&lt;SPAN style="background-color: #ffffff; box-sizing: border-box; color: #333333; display: inline; float: none; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;abbrev_codes&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;&lt;SPAN style="background-color: #ffffff; box-sizing: border-box; color: #333333; display: inline; float: none; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;&amp;gt;&amp;gt;&amp;gt; change &amp;nbsp;abbrev_codes to&amp;nbsp;abbrev_codes2&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;&lt;SPAN style="background-color: #ffffff; box-sizing: border-box; color: #333333; display: inline; float: none; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;abbrev_codes2=tranwrd(abbrev_codes2, list,""); &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;&lt;SPAN style="background-color: #ffffff; box-sizing: border-box; color: #333333; display: inline; float: none; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;&amp;gt;&amp;gt;&amp;gt; Its not worked too, because the substring list = "hxu &amp;nbsp;&amp;nbsp; …. &amp;nbsp; &amp;nbsp; " (lenght = 100 &amp;gt;&amp;gt;&amp;gt; hxu + 97 space blank)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;&lt;SPAN style="background-color: #ffffff; box-sizing: border-box; color: #333333; display: inline; float: none; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;&amp;gt;&amp;gt;&amp;gt; use trim()&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;&lt;SPAN style="background-color: #ffffff; box-sizing: border-box; color: #333333; display: inline; float: none; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt; abbrev_codes2=tranwrd(abbrev_codes2, trim(list),""); &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;&lt;SPAN style="background-color: #ffffff; box-sizing: border-box; color: #333333; display: inline; float: none; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;&amp;gt;&amp;gt;&amp;gt; Now it work, but it is not proper like the result you want&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;&lt;SPAN style="background-color: #ffffff; box-sizing: border-box; color: #333333; display: inline; float: none; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;&amp;gt;&amp;gt;&amp;gt; add line of code to remove ',' in left and rigth of string&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;&lt;SPAN style="background-color: #ffffff; box-sizing: border-box; color: #333333; display: inline; float: none; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;&amp;gt;&amp;gt;&amp;gt; We have;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;&lt;SPAN style="background-color: #ffffff; box-sizing: border-box; color: #333333; display: inline; float: none; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;/********Fix from your code******/&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data art2;
set art2;
length abbrev_codes2 list $100;
abbrev_codes2=abbrev_codes;
do list = "hxu","Hydroxyure","ntiretroviralTreatmentotSpecified","Antiretroviral",
"and","Antiretroviral Treatment Not cified","iretroviral Treatment Not Specified",
"Ant troviral Treatment Not Specified";
abbrev_codes2=tranwrd(abbrev_codes2,trim(list),"");
end;
abbrev_codes2=prxchange("s/ /,/",-1,cats(prxchange("s/,//",-1,abbrev_codes2)));
drop list;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;&lt;SPAN style="background-color: #ffffff; box-sizing: border-box; color: #333333; display: inline; float: none; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;/****OR****/&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data art2;
set art2;
abbrev_codes2=prxchange('s/hxu|Hydroxyure|ntiretroviralTreatmentotSpecified|Antiretroviral|and|Antiretroviral Treatment Not cified|iretroviral Treatment Not Specified|Ant troviral Treatment Not Specified//',-1,abbrev_codes);
abbrev_codes2=prxchange("s/ /,/",-1,cats(prxchange("s/,//",-1,abbrev_codes2)));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN style="display: inline !important; float: none; background-color: #ffffff; color: #333333; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;&lt;SPAN style="background-color: #ffffff; box-sizing: border-box; color: #333333; display: inline; float: none; font-family: Arial,Helvetica,sans-serif; font-size: 14px; font-style: normal; font-variant: normal; font-weight: 300; letter-spacing: normal; line-height: 150%; orphans: 2; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; word-spacing: 0px;"&gt;Have a nice day.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Apr 2020 09:16:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/deleting-substrings-from-a-string/m-p/640646#M190882</guid>
      <dc:creator>kelxxx</dc:creator>
      <dc:date>2020-04-17T09:16:28Z</dc:date>
    </item>
  </channel>
</rss>

