<?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: Adding a comma or removing from a character variable list in SAS 9.4 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-comma-or-removing-from-a-character-variable-list-in-SAS/m-p/806105#M317564</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/83652"&gt;@inquistive&lt;/a&gt;&amp;nbsp;, Is this list at the row level? You can use the TRANWRD function to replace the comma for a space for an empty string for example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HarrySnart_0-1649175444330.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70133iA10BB8670BE7D4C8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HarrySnart_0-1649175444330.png" alt="HarrySnart_0-1649175444330.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
have = "Michael, Mitta, George";
want = tranwrd(have,",","");
put have;
put want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 05 Apr 2022 16:17:40 GMT</pubDate>
    <dc:creator>HarrySnart</dc:creator>
    <dc:date>2022-04-05T16:17:40Z</dc:date>
    <item>
      <title>Adding a comma or removing from a character variable list in SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-comma-or-removing-from-a-character-variable-list-in-SAS/m-p/806094#M317560</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please help me how to remove &lt;STRONG&gt;comma&lt;/STRONG&gt; ("&lt;STRONG&gt;,&lt;/STRONG&gt;") from a list within a character variable values&amp;nbsp;&lt;/P&gt;
&lt;P&gt;for the following scenario ?&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Var&amp;nbsp;&lt;/U&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;U&gt;Values&amp;nbsp;&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Name&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Michael, Mitta, George&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you could tell me how to add a comma between words/strings in for the following scenario;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Var&amp;nbsp;&lt;/U&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;U&gt; Values&amp;nbsp;&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Name&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Michael&amp;nbsp; Mitta George&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;Thanks for support in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2022 15:54:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-comma-or-removing-from-a-character-variable-list-in-SAS/m-p/806094#M317560</guid>
      <dc:creator>inquistive</dc:creator>
      <dc:date>2022-04-05T15:54:56Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a comma or removing from a character variable list in SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-comma-or-removing-from-a-character-variable-list-in-SAS/m-p/806103#M317563</link>
      <description>&lt;P&gt;Use the TRANSTRN function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
string = "Michael, Mitta, George";
string = transtrn(string,", "," ");
put string= $quote.;
string = transtrn(string," ",", ");
put string= $quote.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Apr 2022 16:17:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-comma-or-removing-from-a-character-variable-list-in-SAS/m-p/806103#M317563</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-05T16:17:07Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a comma or removing from a character variable list in SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-comma-or-removing-from-a-character-variable-list-in-SAS/m-p/806105#M317564</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/83652"&gt;@inquistive&lt;/a&gt;&amp;nbsp;, Is this list at the row level? You can use the TRANWRD function to replace the comma for a space for an empty string for example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HarrySnart_0-1649175444330.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/70133iA10BB8670BE7D4C8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HarrySnart_0-1649175444330.png" alt="HarrySnart_0-1649175444330.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
have = "Michael, Mitta, George";
want = tranwrd(have,",","");
put have;
put want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Apr 2022 16:17:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-comma-or-removing-from-a-character-variable-list-in-SAS/m-p/806105#M317564</guid>
      <dc:creator>HarrySnart</dc:creator>
      <dc:date>2022-04-05T16:17:40Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a comma or removing from a character variable list in SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-comma-or-removing-from-a-character-variable-list-in-SAS/m-p/806107#M317565</link>
      <description>&lt;P&gt;Remove a character : Compress function&lt;/P&gt;
&lt;PRE&gt;data example;
   var = "Michael, Mitta, George";
   var = compress(var,',');
run;&lt;/PRE&gt;
&lt;P&gt;You don't show what the "inserted" version might be. If you are actually adding characters, such as to replace a single space with comma and space you may need to create a new variable as when you add characters you run the risk of exceeding the defined length of the existing variable leading to truncation of the last word. If you only have &lt;STRONG&gt;exactly&lt;/STRONG&gt; one space then perhaps this is easiest:&lt;/P&gt;
&lt;PRE&gt;data example2;
   var= "Michael Mitta George";
   newvar= tranwrd(var,' ',', ');
run;&lt;/PRE&gt;
&lt;P&gt;If you don't want to have comma and a space you can use Translate function to replace the single space with a single comma. Just switch the positions of the comma and space in the first example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Apr 2022 16:20:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-comma-or-removing-from-a-character-variable-list-in-SAS/m-p/806107#M317565</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-04-05T16:20:31Z</dc:date>
    </item>
    <item>
      <title>Re: Adding a comma or removing from a character variable list in SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-a-comma-or-removing-from-a-character-variable-list-in-SAS/m-p/806110#M317568</link>
      <description>&lt;P&gt;How consistent are your source strings about what characters are between the "words" in the list?&lt;/P&gt;
&lt;P&gt;If you always have comma and space then just removing the commas will work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   values = compress(values,',');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Put if you sometimes have only the comma between the words then that would cause two words to merge.&lt;/P&gt;
&lt;P&gt;You could replace the comma with a space&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;values=translate(values,' ',',');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But if you sometimes also have spaces then you might have two spaces between some pairs of words.&lt;/P&gt;
&lt;P&gt;So perhaps you want to use COMPBL() to collapse those into one space.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;values=compbl(translate(values,' ',','));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Apr 2022 16:46:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-a-comma-or-removing-from-a-character-variable-list-in-SAS/m-p/806110#M317568</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-04-05T16:46:29Z</dc:date>
    </item>
  </channel>
</rss>

