<?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: Replace a Space with a Dash in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-Space-with-a-Dash/m-p/463938#M118261</link>
    <description>&lt;P&gt;Precisely why I suggested using pattern matching. That one is easy to correct:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
  address='12 345 main street.';
  output;
  address='345 main street.';
  output;
  address='345 1st avenue';
  output;
run;

data want;
  set have;
  address = prxchange('s/(\d+) (\d+) /$1-$2 /', -1, address);
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 22 May 2018 00:09:06 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2018-05-22T00:09:06Z</dc:date>
    <item>
      <title>Replace a Space with a Dash</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-Space-with-a-Dash/m-p/463872#M118243</link>
      <description>&lt;P&gt;This might be easy, but I keep getting hung up on this. &amp;nbsp;I am trying to replace a space with a dash within an address field. &amp;nbsp;For instance, the address is listed as 12 345 main street. &amp;nbsp;I am trying to get it to add a dash, but only in the first space i.e. 12-345 main street. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate the assistance.&lt;/P&gt;</description>
      <pubDate>Mon, 21 May 2018 20:27:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-Space-with-a-Dash/m-p/463872#M118243</guid>
      <dc:creator>Lost_Gary</dc:creator>
      <dc:date>2018-05-21T20:27:49Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a Space with a Dash</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-Space-with-a-Dash/m-p/463874#M118244</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; 
data w;
k='12 345 main street.';
substr(k,index(k,' '),1)='-';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 21 May 2018 20:31:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-Space-with-a-Dash/m-p/463874#M118244</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-21T20:31:26Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a Space with a Dash</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-Space-with-a-Dash/m-p/463882#M118247</link>
      <description>&lt;P&gt;Brilliant. &amp;nbsp;Thank you. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 May 2018 20:58:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-Space-with-a-Dash/m-p/463882#M118247</guid>
      <dc:creator>Lost_Gary</dc:creator>
      <dc:date>2018-05-21T20:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a Space with a Dash</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-Space-with-a-Dash/m-p/463886#M118249</link>
      <description>&lt;P&gt;While you've marked this question as solved, unless all of your addresses have that pattern of numbers, I think you will be exchanging a number of spaces for hyphens where you don't really want to.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'd suggest using pattern matching. E.g.,&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  address='12 345 main street.';
  output;
  address='345 main street.';
  output;
run;

data want;
  set have;
  address = prxchange('s/(\d+) (\d+)/$1-$2/', -1, address);
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 May 2018 21:14:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-Space-with-a-Dash/m-p/463886#M118249</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-05-21T21:14:23Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a Space with a Dash</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-Space-with-a-Dash/m-p/463931#M118258</link>
      <description>&lt;P&gt;ooh, I like the efficiency in that coding and also learning different ways. &amp;nbsp;So a thumbs up for this method as well. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem with addresses that I am finding, is the scenario of the address '345 1st avenue' as '345-1st avenue' would be inaccurate (for this scenario). &amp;nbsp;So,&amp;nbsp;my less than efficient solution was to create different 'rules' to isolate the scenarios in which the 'substr' function works better to replace some of the spaces. &amp;nbsp;I know what i am doing isn't perfect. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 21 May 2018 23:33:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-Space-with-a-Dash/m-p/463931#M118258</guid>
      <dc:creator>Lost_Gary</dc:creator>
      <dc:date>2018-05-21T23:33:51Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a Space with a Dash</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-Space-with-a-Dash/m-p/463938#M118261</link>
      <description>&lt;P&gt;Precisely why I suggested using pattern matching. That one is easy to correct:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
  address='12 345 main street.';
  output;
  address='345 main street.';
  output;
  address='345 1st avenue';
  output;
run;

data want;
  set have;
  address = prxchange('s/(\d+) (\d+) /$1-$2 /', -1, address);
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 May 2018 00:09:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-Space-with-a-Dash/m-p/463938#M118261</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-05-22T00:09:06Z</dc:date>
    </item>
  </channel>
</rss>

