<?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: How to insert ‘-’ in 12 digit number between every 4 digit so that output will like : 1234-5678- in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-insert-in-12-digit-number-between-every-4-digit-so-that/m-p/589244#M168507</link>
    <description>i tested the program before posting it and it worked fine. i dont see why it would generate an issue at your end.. in my code i made sure that whatever the length of the input string, the output string would have extra length, that too the number of - in it. so if your sting is 12 chars long, the output string will be 15 chars long&lt;BR /&gt;</description>
    <pubDate>Tue, 17 Sep 2019 03:58:20 GMT</pubDate>
    <dc:creator>VinitvictorCorr</dc:creator>
    <dc:date>2019-09-17T03:58:20Z</dc:date>
    <item>
      <title>How to insert ‘-’ in 12 digit number between every 4 digit so that output will like : 1234-5678-9</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-insert-in-12-digit-number-between-every-4-digit-so-that/m-p/588920#M168367</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;hi All,&lt;/P&gt;&lt;P&gt;can some please help me to get the desired data, I want number from 123456789101 to like this :1234-5678-9101....??&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input number;
value=substr(number,1,4)||'-'||substr(number,5,7)||'-'||substr(number,8);
cards;
123456789101
;run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2019 00:52:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-insert-in-12-digit-number-between-every-4-digit-so-that/m-p/588920#M168367</guid>
      <dc:creator>varmal</dc:creator>
      <dc:date>2019-09-16T00:52:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert ‘-’ in 12 digit number between every 4 digit so that output will like : 1234-5678-</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-insert-in-12-digit-number-between-every-4-digit-so-that/m-p/588921#M168368</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
picture num
low-high ='9999-9999-9999';
run;


data a;
input number;
value=put(number,num.);
cards;
123456789101
;run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Sep 2019 01:04:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-insert-in-12-digit-number-between-every-4-digit-so-that/m-p/588921#M168368</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-16T01:04:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert ‘-’ in 12 digit number between every 4 digit so that output will like : 1234-5678-</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-insert-in-12-digit-number-between-every-4-digit-so-that/m-p/588926#M168370</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
input number;
array t(3) $4 _temporary_;
call pokelong(put(number,best12.),addrlong(t(1)),12);
value=catx('-',of t(*));
cards;
123456789101
;run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Sep 2019 01:51:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-insert-in-12-digit-number-between-every-4-digit-so-that/m-p/588926#M168370</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-09-16T01:51:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert ‘-’ in 12 digit number between every 4 digit so that output will like : 1234-5678-</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-insert-in-12-digit-number-between-every-4-digit-so-that/m-p/588930#M168373</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/290471"&gt;@varmal&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Your own attempt would work if you executed it a bit more diligently:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a (drop = _:) ;                                                         
  input number ;                                                             
  _c = put (number, z12.) ;                                                  
  value = substr (_c,1,4) || '-' || substr (_c,5,4) || '-' || substr (_c,9) ;
  cards ;                                                                    
123456789101                                                                 
;                                                                            
run ;                                                                        
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;_C prevents the step from generating data type conversion notes. Alternatively, you can use a loop to save some keystrokes:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a ;                                                                                                                                
  input number ;                                                                                                                        
  length value $ 14 ;                                                                                                                   
  do _n_ = 1, 5, 9 ;                                                                                                                    
    value = catx ("-", value, substr (put (number, z12.), _n_, 4)) ;                                                                    
  end ;                                                                                                                                 
  put value= ;                                                                                                                          
  cards ;                                                                                                                               
123456789101                                                                                                                            
;                                                                                                                                       
run ;                                                         
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Having said that, I think that the picture format approach offered by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;is a neater solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2019 03:24:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-insert-in-12-digit-number-between-every-4-digit-so-that/m-p/588930#M168373</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-09-16T03:24:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert ‘-’ in 12 digit number between every 4 digit so that output will like : 1234-5678-</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-insert-in-12-digit-number-between-every-4-digit-so-that/m-p/588940#M168374</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	x=123456789101;
	y=prxchange('s/(\d{4})(\d{4})(\d{4})/$1-$2-$3/', -1, x);
	put y=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Sep 2019 05:11:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-insert-in-12-digit-number-between-every-4-digit-so-that/m-p/588940#M168374</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-09-16T05:11:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert ‘-’ in 12 digit number between every 4 digit so that output will like : 1234-5678-</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-insert-in-12-digit-number-between-every-4-digit-so-that/m-p/588941#M168375</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Wow. I admire your ability to put this kind of expression together.&lt;/P&gt;
&lt;P&gt;But frankly,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;'s picture format 9999-9999-9999 looks much more self-explanatory to me, plus it doesn't generate implicit data type conversion notes in the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2019 05:49:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-insert-in-12-digit-number-between-every-4-digit-so-that/m-p/588941#M168375</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-09-16T05:49:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert ‘-’ in 12 digit number between every 4 digit so that output will like : 1234-5678-</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-insert-in-12-digit-number-between-every-4-digit-so-that/m-p/588942#M168376</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp;I could not agree more, picture formats are the way to go here &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2019 05:51:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-insert-in-12-digit-number-between-every-4-digit-so-that/m-p/588942#M168376</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-09-16T05:51:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert ‘-’ in 12 digit number between every 4 digit so that output will like : 1234-5678-</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-insert-in-12-digit-number-between-every-4-digit-so-that/m-p/588950#M168377</link>
      <description>&lt;P&gt;If the length of the number is not known, you can use the below code:&lt;/P&gt;&lt;P&gt;In your case its 12 so it would be much simpler&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data a(keep=s z);&lt;BR /&gt;s="123456789";&lt;BR /&gt;%macro nums;&lt;BR /&gt;c=length(s);&lt;BR /&gt;call symput('p',put(c,best.));&lt;BR /&gt;l=int(c/4);&lt;BR /&gt;call symput('k',put(l,best.));&lt;BR /&gt;%do i=1 %to &amp;amp;k.;&lt;BR /&gt;%if &amp;amp;i.=1 %then %do;&lt;BR /&gt;a&amp;amp;i.=substr(s,1,4);&lt;BR /&gt;%end;&lt;BR /&gt;%if &amp;amp;i. ne 1 %then %do;&lt;BR /&gt;a&amp;amp;i.=substr(s,(&amp;amp;i.-1)*4+1,4);&lt;BR /&gt;%end;&lt;BR /&gt;%if &amp;amp;i.=&amp;amp;k. %then %do;&lt;BR /&gt;%let m=%sysevalf(&amp;amp;k.+1,integer);&lt;BR /&gt;%put &amp;amp;m.;&lt;BR /&gt;a&amp;amp;m.=substr(s,(&amp;amp;i)*4+1);&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;length z $%sysevalf(&amp;amp;p.+&amp;amp;m.,integer).;&lt;BR /&gt;%do j=1 %to &amp;amp;m.;&lt;BR /&gt;%if &amp;amp;j.=1 %then %do;&lt;BR /&gt;z=a&amp;amp;j.;&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&lt;BR /&gt;z=cats(z,"-",trim(a&amp;amp;j.));&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%mend nums;&lt;BR /&gt;%nums;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2019 06:26:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-insert-in-12-digit-number-between-every-4-digit-so-that/m-p/588950#M168377</guid>
      <dc:creator>VinitvictorCorr</dc:creator>
      <dc:date>2019-09-16T06:26:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert ‘-’ in 12 digit number between every 4 digit so that output will like : 1234-5678-</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-insert-in-12-digit-number-between-every-4-digit-so-that/m-p/588987#M168388</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/289580"&gt;@VinitvictorCorr&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As an opinion: O.K. as an exercise but in real live: Picture Format!&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2019 10:25:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-insert-in-12-digit-number-between-every-4-digit-so-that/m-p/588987#M168388</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-09-16T10:25:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert ‘-’ in 12 digit number between every 4 digit so that output will like : 1234-5678-</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-insert-in-12-digit-number-between-every-4-digit-so-that/m-p/589105#M168435</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/289580"&gt;@VinitvictorCorr&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;1. I'd suggest that you test your solution before posting it:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Did you notice that it doesn't work since the macro variable K that is supposed to be populated by SYMPUT is not resolved when it's dereferenced as the upper bound of the %DO loop?&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;How do you expect K - and P - to be populated by the SYMPUT call, active only during the DATA step run time, during the macro execution time that occurs earlier? Note that just because you &lt;EM&gt;coded&lt;/EM&gt; the macro inside the DATA step doesn't change this behavior.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;2. If your intent is to set the length of the character variable Z based on the number of digits in the digit string S determined at run time - or any other quantity determined at run time - it cannot be done because it is set at compile time; and the DATA step is not a time machine. You can only set the length of Z to the length of S by assigning Z=S, but then you won't have enough room for the intervening dashes.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. Under the OP's conditions, the input variable NUMBER is a numeric variable whose value is integer. Even if setting the length of the "dashed" output string &lt;EM&gt;were&lt;/EM&gt; possible at run time - say, based on the expression ceil(log10(number)), - it would be a wasted effort since the integer precision of a SAS numeric variable is limited to 15 digits under ASCII and 16 under EBCDIC, which means that under no circumstances you can have more than 3 dashes separating every 4 consecutive digits.&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Sep 2019 15:58:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-insert-in-12-digit-number-between-every-4-digit-so-that/m-p/589105#M168435</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-09-16T15:58:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert ‘-’ in 12 digit number between every 4 digit so that output will like : 1234-5678-</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-insert-in-12-digit-number-between-every-4-digit-so-that/m-p/589244#M168507</link>
      <description>i tested the program before posting it and it worked fine. i dont see why it would generate an issue at your end.. in my code i made sure that whatever the length of the input string, the output string would have extra length, that too the number of - in it. so if your sting is 12 chars long, the output string will be 15 chars long&lt;BR /&gt;</description>
      <pubDate>Tue, 17 Sep 2019 03:58:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-insert-in-12-digit-number-between-every-4-digit-so-that/m-p/589244#M168507</guid>
      <dc:creator>VinitvictorCorr</dc:creator>
      <dc:date>2019-09-17T03:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to insert ‘-’ in 12 digit number between every 4 digit so that output will like : 1234-5678-</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-insert-in-12-digit-number-between-every-4-digit-so-that/m-p/589246#M168509</link>
      <description>&lt;P&gt;sorry my bad.. &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt; &lt;span class="lia-unicode-emoji" title=":face_with_tongue:"&gt;😛&lt;/span&gt; . Got what you wanted to say. I tweeked it a bit. I think this will work now&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data a(keep=s z);&lt;BR /&gt;s="123456789";&lt;BR /&gt;%macro nums;&lt;BR /&gt;c=length(s);&lt;BR /&gt;c1=put(c,best.);&lt;BR /&gt;call symput('p',c1);&lt;BR /&gt;l=int(c/4);&lt;BR /&gt;l1=put(l,best.);&lt;BR /&gt;call symput('k',l1);&lt;BR /&gt;%do i=1 %to &amp;amp;k.;&lt;BR /&gt;%if &amp;amp;i.=1 %then %do;&lt;BR /&gt;a&amp;amp;i.=substr(s,1,4);&lt;BR /&gt;%end;&lt;BR /&gt;%if &amp;amp;i. ne 1 %then %do;&lt;BR /&gt;a&amp;amp;i.=substr(s,(&amp;amp;i.-1)*4+1,4);&lt;BR /&gt;%end;&lt;BR /&gt;%if &amp;amp;i.=&amp;amp;k. %then %do;&lt;BR /&gt;%let m=%sysevalf(&amp;amp;k.+1,integer);&lt;BR /&gt;%put &amp;amp;m.;&lt;BR /&gt;a&amp;amp;m.=substr(s,(&amp;amp;i)*4+1);&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;length z $%sysevalf(&amp;amp;p.+&amp;amp;m.,integer).;&lt;BR /&gt;%do j=1 %to &amp;amp;m.;&lt;BR /&gt;%if &amp;amp;j.=1 %then %do;&lt;BR /&gt;z=a&amp;amp;j.;&lt;BR /&gt;%end;&lt;BR /&gt;%else %do;&lt;BR /&gt;z=cats(z,"-",trim(a&amp;amp;j.));&lt;BR /&gt;%end;&lt;BR /&gt;%end;&lt;BR /&gt;%mend nums;&lt;BR /&gt;%nums;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know if this works &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2019 04:14:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-insert-in-12-digit-number-between-every-4-digit-so-that/m-p/589246#M168509</guid>
      <dc:creator>VinitvictorCorr</dc:creator>
      <dc:date>2019-09-17T04:14:25Z</dc:date>
    </item>
  </channel>
</rss>

