<?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: Formatting comma values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Formatting-comma-values/m-p/634433#M188297</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37814"&gt;@Walternate&lt;/a&gt;&amp;nbsp; Whilst the known fact being sage Tom's solution of course slick, smart and fast, I wanted to try a solution using Regular expression.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input Name $20.;
cards;
Smith,John B
Doe,   Jane M
Jones   , Jim
;

data want;
 set have;
 new_name= prxchange('s/(\w+)\s*,\s*(\w+)\s*(\w+)?/$1, $2 $3/', -1, name);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.WANT" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col"&gt;Name&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;new_name&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;Smith,John B&lt;/TD&gt;
&lt;TD class="l data"&gt;Smith, John B&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;Doe, Jane M&lt;/TD&gt;
&lt;TD class="l data"&gt;Doe, Jane M&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;Jones , Jim&lt;/TD&gt;
&lt;TD class="l data"&gt;Jones, Jim&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
    <pubDate>Tue, 24 Mar 2020 14:22:58 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-03-24T14:22:58Z</dc:date>
    <item>
      <title>Formatting comma values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-comma-values/m-p/634424#M188292</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have data with a name variable which is usually (but not always) formatted Last, First Middle. I want to do a little cleaning to make sure that for those values with a comma, there is no space between Last and the comma, and there is one (and only one) space between the comma and First.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Name&lt;/P&gt;&lt;P&gt;Smith,John B&lt;/P&gt;&lt;P&gt;Doe,&amp;nbsp; &amp;nbsp;Jane M&lt;/P&gt;&lt;P&gt;Jones&amp;nbsp; &amp;nbsp;, Jim&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Values can have 0 to multiple spaces both before and after the comma, so all these scenarios need to be accounted for.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The desired output would be:&lt;/P&gt;&lt;P&gt;Name&lt;/P&gt;&lt;P&gt;Smith, John B&lt;/P&gt;&lt;P&gt;Doe, Jane M&lt;/P&gt;&lt;P&gt;Jones, Jim&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ie, last name, then comma (no space between), then a single space, then first, then middle.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was thinking of using tranwrd to replace space+comma with just comma, and comma+multiple spaces/zero spaces with comma+one space, but since there can be multiple spaces, there'd have to be some sort of iteration/passing through mulitple times and I couldn't figure out how to set that up.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is much appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2020 13:25:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-comma-values/m-p/634424#M188292</guid>
      <dc:creator>Walternate</dc:creator>
      <dc:date>2020-03-24T13:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting comma values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-comma-values/m-p/634428#M188296</link>
      <description>&lt;P&gt;Add a space after every comma.&amp;nbsp; Replace multiple spaces with one space. Remove space before comma.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;want=tranwrd(compbl(tranwrd(have,',',', ')),' ,',',');&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Mar 2020 13:52:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-comma-values/m-p/634428#M188296</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-03-24T13:52:21Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting comma values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-comma-values/m-p/634433#M188297</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37814"&gt;@Walternate&lt;/a&gt;&amp;nbsp; Whilst the known fact being sage Tom's solution of course slick, smart and fast, I wanted to try a solution using Regular expression.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input Name $20.;
cards;
Smith,John B
Doe,   Jane M
Jones   , Jim
;

data want;
 set have;
 new_name= prxchange('s/(\w+)\s*,\s*(\w+)\s*(\w+)?/$1, $2 $3/', -1, name);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.WANT" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col"&gt;Name&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;new_name&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;Smith,John B&lt;/TD&gt;
&lt;TD class="l data"&gt;Smith, John B&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;Doe, Jane M&lt;/TD&gt;
&lt;TD class="l data"&gt;Doe, Jane M&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;Jones , Jim&lt;/TD&gt;
&lt;TD class="l data"&gt;Jones, Jim&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Tue, 24 Mar 2020 14:22:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-comma-values/m-p/634433#M188297</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-24T14:22:58Z</dc:date>
    </item>
    <item>
      <title>Re: Formatting comma values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formatting-comma-values/m-p/634708#M188404</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Name $20.;
cards;
Smith,John B
Doe,   Jane M
Jones   , Jim
;

data want;
 set have;
 new_name= left(prxchange('s/\b(\w+)\b/ $1 /', -1, name));
run;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Mar 2020 12:04:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formatting-comma-values/m-p/634708#M188404</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-03-25T12:04:00Z</dc:date>
    </item>
  </channel>
</rss>

