<?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 print a record with leading zeros by ignoring special characters? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-print-a-record-with-leading-zeros-by-ignoring-special/m-p/168485#M32353</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;data have;
&amp;nbsp; infile datalines truncover;
&amp;nbsp; input mystring $20.;
&amp;nbsp; datalines;
9161-642-524
9161-7642525
9167642526
642526
642
;
run;
data want;
 set have;
 length temp $ 5;
 temp=mystring;
 want=input(compress(temp,,'kd'),best.);
 format want z5.;
run;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 20 Aug 2014 13:44:39 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2014-08-20T13:44:39Z</dc:date>
    <item>
      <title>How to print a record with leading zeros by ignoring special characters?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-print-a-record-with-leading-zeros-by-ignoring-special/m-p/168480#M32348</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've my inputs as below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;9161-642-524 &lt;/P&gt;&lt;P&gt;9161-7642525 &lt;/P&gt;&lt;P&gt;9167642526 &lt;/P&gt;&lt;P&gt;642526 &lt;/P&gt;&lt;P&gt;642&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need ouput as follows&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;09161&lt;/P&gt;&lt;P&gt;09161&lt;/P&gt;&lt;P&gt;91676&lt;/P&gt;&lt;P&gt;64252&lt;/P&gt;&lt;P&gt;00642&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It means I need only 5 digits in output. If we've any speacial characters or the input record is less than 5 digits then we need to ignore those records and it should be produced with leading zeros.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tried this with substr and length function also with the format Z5. But it doesn't helped me either.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Aug 2014 07:54:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-print-a-record-with-leading-zeros-by-ignoring-special/m-p/168480#M32348</guid>
      <dc:creator>RamKumar</dc:creator>
      <dc:date>2014-08-20T07:54:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to print a record with leading zeros by ignoring special characters?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-print-a-record-with-leading-zeros-by-ignoring-special/m-p/168481#M32349</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here you have one solution:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc format;&lt;/P&gt;&lt;P&gt;picture frm &lt;/P&gt;&lt;P&gt; low-high='99999';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have (keep=varwant want) ;&lt;/P&gt;&lt;P&gt;length want 5 ;&lt;/P&gt;&lt;P&gt;input varwant $30.;&lt;/P&gt;&lt;P&gt;dashpos=index(varwant, "-");&lt;/P&gt;&lt;P&gt;if 1 &amp;lt;= dashpos &amp;lt;= 5 then want=substr(varwant,1,dashpos - 1);&lt;/P&gt;&lt;P&gt;else want=substr(varwant,1,5);&lt;/P&gt;&lt;P&gt;format want frm.;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;9161-642-524 &lt;/P&gt;&lt;P&gt;9161-7642525 &lt;/P&gt;&lt;P&gt;9167642526 &lt;/P&gt;&lt;P&gt;642526 &lt;/P&gt;&lt;P&gt;642&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Aug 2014 09:47:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-print-a-record-with-leading-zeros-by-ignoring-special/m-p/168481#M32349</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2014-08-20T09:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to print a record with leading zeros by ignoring special characters?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-print-a-record-with-leading-zeros-by-ignoring-special/m-p/168482#M32350</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Below is totally over the top in case this is a once-off task. If it is something you need regularly then you might consider the approach.&lt;/P&gt;&lt;P&gt;It is based on &lt;A href="http://support.sas.com/documentation/cdl/en/proc/67327/HTML/default/viewer.htm#p1gg77jyhc9s42n1f1vjyx2hsg8b.htm" title="http://support.sas.com/documentation/cdl/en/proc/67327/HTML/default/viewer.htm#p1gg77jyhc9s42n1f1vjyx2hsg8b.htm"&gt;Base SAS(R) 9.4 Procedures Guide, Third Edition&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc fcmp outlib=work.functions.smd;&lt;/P&gt;&lt;P&gt;&amp;nbsp; function print_str(in_str $) $;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; r=put(input(scan(in_str,1,,'kd'),5.),z5.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return(r);&lt;/P&gt;&lt;P&gt;&amp;nbsp; endsub;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;options cmplib=(work.functions);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc format;&lt;/P&gt;&lt;P&gt;&amp;nbsp; value $print_str (default=5) other=[print_str()];&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; infile datalines truncover;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input mystring $10.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; datalines;&lt;/P&gt;&lt;P&gt;9161-642-524&lt;/P&gt;&lt;P&gt;9161-7642525&lt;/P&gt;&lt;P&gt;9167642526&lt;/P&gt;&lt;P&gt;642526&lt;/P&gt;&lt;P&gt;642&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc print data=have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; format mystring $print_str.;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Aug 2014 11:05:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-print-a-record-with-leading-zeros-by-ignoring-special/m-p/168482#M32350</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2014-08-20T11:05:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to print a record with leading zeros by ignoring special characters?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-print-a-record-with-leading-zeros-by-ignoring-special/m-p/168483#M32351</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Data A;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Input N $;&lt;/P&gt;&lt;P&gt;&amp;nbsp; N5_Text=Put(Input(Substr(Scan(Compress(N),1,'-'),1,5),5.),Z5.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; N5_Num=Input(Substr(Scan(Compress(N),1,'-'),1,5),5.); Format N5_Num Z5.;&lt;/P&gt;&lt;P&gt;&amp;nbsp; Datalines;&lt;/P&gt;&lt;P&gt;9161-642-524 &lt;/P&gt;&lt;P&gt;9161-7642525 &lt;/P&gt;&lt;P&gt;9167642526 &lt;/P&gt;&lt;P&gt;642526 &lt;/P&gt;&lt;P&gt;642&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;Run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Aug 2014 12:06:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-print-a-record-with-leading-zeros-by-ignoring-special/m-p/168483#M32351</guid>
      <dc:creator>user24feb</dc:creator>
      <dc:date>2014-08-20T12:06:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to print a record with leading zeros by ignoring special characters?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-print-a-record-with-leading-zeros-by-ignoring-special/m-p/168484#M32352</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I believe you could simplify your nested functions as below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;N5_Text&lt;/SPAN&gt;=put(input(scan(N,1,,'kd'),5.),z5.);&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;N5_Text&lt;/SPAN&gt;=input(scan(N,1,,'kd'),5.);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Aug 2014 13:15:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-print-a-record-with-leading-zeros-by-ignoring-special/m-p/168484#M32352</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2014-08-20T13:15:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to print a record with leading zeros by ignoring special characters?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-print-a-record-with-leading-zeros-by-ignoring-special/m-p/168485#M32353</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE&gt;data have;
&amp;nbsp; infile datalines truncover;
&amp;nbsp; input mystring $20.;
&amp;nbsp; datalines;
9161-642-524
9161-7642525
9167642526
642526
642
;
run;
data want;
 set have;
 length temp $ 5;
 temp=mystring;
 want=input(compress(temp,,'kd'),best.);
 format want z5.;
run;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Xia Keshan&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Aug 2014 13:44:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-print-a-record-with-leading-zeros-by-ignoring-special/m-p/168485#M32353</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-08-20T13:44:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to print a record with leading zeros by ignoring special characters?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-print-a-record-with-leading-zeros-by-ignoring-special/m-p/168486#M32354</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just to be "picky": What about a source string like "916-7642525"?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Aug 2014 13:57:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-print-a-record-with-leading-zeros-by-ignoring-special/m-p/168486#M32354</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2014-08-20T13:57:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to print a record with leading zeros by ignoring special characters?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-print-a-record-with-leading-zeros-by-ignoring-special/m-p/168487#M32355</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Not sure. Maybe I misunderstood OP's meaning .&amp;nbsp; Let OP judge it anyway .&amp;nbsp; Patrick.Matter&amp;nbsp; !&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 20 Aug 2014 15:01:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-print-a-record-with-leading-zeros-by-ignoring-special/m-p/168487#M32355</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2014-08-20T15:01:08Z</dc:date>
    </item>
  </channel>
</rss>

