<?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 dashes into a string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-dashes-into-a-string/m-p/684560#M207474</link>
    <description>&lt;PRE&gt;data _null_;
x=123456789;
y=put(x,ssn.);
put x= / y=;
run;&lt;/PRE&gt;</description>
    <pubDate>Thu, 17 Sep 2020 12:06:04 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2020-09-17T12:06:04Z</dc:date>
    <item>
      <title>Adding dashes into a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-dashes-into-a-string/m-p/684358#M207379</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to add dashes in the middle of a string of social security numbers. For example, 123456789 -&amp;gt; 123-45-6789.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been trying to use the cat and substr commands, but I don't think I'm totally understanding how the substr function works. I'm still new to SAS.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;length ssn_dash $11;&lt;BR /&gt;ssn_dash = ssn;&lt;BR /&gt;ssn_dash = cat(substr(ssn_dash,1,3), '-', substr(ssn_dash,3));&lt;BR /&gt;ssn_dash = cat(substr(ssn_dash,1,6), '-', substr(ssn_dash,6));&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any advice would be greatly appreciated!&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2020 19:53:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-dashes-into-a-string/m-p/684358#M207379</guid>
      <dc:creator>smg3141</dc:creator>
      <dc:date>2020-09-16T19:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: Adding dashes into a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-dashes-into-a-string/m-p/684361#M207381</link>
      <description>&lt;P&gt;Assuming ssn is a character string variable:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ssn_dash = catx("-", substr(ssn,1,3), substr(ssn,4,2), substr(ssn,6));&lt;/P&gt;</description>
      <pubDate>Wed, 16 Sep 2020 20:11:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-dashes-into-a-string/m-p/684361#M207381</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-09-16T20:11:54Z</dc:date>
    </item>
    <item>
      <title>Re: Adding dashes into a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-dashes-into-a-string/m-p/684482#M207422</link>
      <description>&lt;P&gt;You were very close.&amp;nbsp; The only adjustment that you would need would be to do add 1 to the last argument of your second substring on each line:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_0-1600310827891.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49482iB2E1BBECC266D7EF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jimbarbour_0-1600310827891.png" alt="jimbarbour_0-1600310827891.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Then you get just what you were after:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jimbarbour_2-1600310893519.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/49484iE5651D826E3B8563/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jimbarbour_2-1600310893519.png" alt="jimbarbour_2-1600310893519.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, that said, I think it's typically better to just do it all in one line as&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;suggests.&amp;nbsp; Notice also that he/she uses CATX instead of just CAT.&amp;nbsp; The CATX function puts a value in between each of the subsequent specified values so that you don't have to code '-' multiple times.&amp;nbsp; Nice function to know about.&amp;nbsp; I also find CATS to be useful.&amp;nbsp; CATS is the about the same as CAT except that it executes a STRIP function on each term.&amp;nbsp; CATS would be like coding CAT(STRIP(Var1), STRIP(Var2), STRIP(Var3)).&amp;nbsp; Very useful in my opinion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Jim&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 17 Sep 2020 02:52:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-dashes-into-a-string/m-p/684482#M207422</guid>
      <dc:creator>jimbarbour</dc:creator>
      <dc:date>2020-09-17T02:52:04Z</dc:date>
    </item>
    <item>
      <title>Re: Adding dashes into a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-dashes-into-a-string/m-p/684560#M207474</link>
      <description>&lt;PRE&gt;data _null_;
x=123456789;
y=put(x,ssn.);
put x= / y=;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 17 Sep 2020 12:06:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-dashes-into-a-string/m-p/684560#M207474</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-09-17T12:06:04Z</dc:date>
    </item>
  </channel>
</rss>

