<?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: Add (0) in prefix wherever the length less then “3”  for Character variable using sas in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338870#M77257</link>
    <description>Thanks for the replay.</description>
    <pubDate>Tue, 07 Mar 2017 16:01:24 GMT</pubDate>
    <dc:creator>sivastat08</dc:creator>
    <dc:date>2017-03-07T16:01:24Z</dc:date>
    <item>
      <title>Add (0) in prefix wherever the length less then “3”  for Character variable using sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338825#M77240</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I want to Add zero(0) in prefix wherever the length(&lt;STRONG&gt;Have&lt;/STRONG&gt;) less then “3” &amp;nbsp;and blank as blank.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Have&lt;/TD&gt;&lt;TD&gt;Length&lt;/TD&gt;&lt;TD&gt;Want&lt;/TD&gt;&lt;TD&gt;Length&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;112&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;112&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;012&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR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t;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;kindly help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Siva&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 15:07:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338825#M77240</guid>
      <dc:creator>sivastat08</dc:creator>
      <dc:date>2017-03-07T15:07:58Z</dc:date>
    </item>
    <item>
      <title>Re: Add (0) in prefix wherever the length less then “3”  for Character variable using sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338831#M77244</link>
      <description>&lt;P&gt;both have and want variables should be a char type: (code fixed)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;length want $10; &amp;nbsp; /* adapt length to max length of have */&lt;/P&gt;
&lt;P&gt;len = length(strip(have));&lt;/P&gt;
&lt;P&gt;if len &amp;lt; 3 then want = substr('00',1,3-len) || left(have);&lt;/P&gt;
&lt;P&gt;else have = want;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 20:30:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338831#M77244</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-03-07T20:30:39Z</dc:date>
    </item>
    <item>
      <title>Re: Add (0) in prefix wherever the length less then “3”  for Character variable using sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338838#M77245</link>
      <description>&lt;P&gt;Here's one approach, within a DATA step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select (lengthn(have));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; when (1) want = '00' || have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; when (2) want = '0' || have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; otherwise want=have;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 15:32:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338838#M77245</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-03-07T15:32:08Z</dc:date>
    </item>
    <item>
      <title>Re: Add (0) in prefix wherever the length less then “3”  for Character variable using sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338850#M77249</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/90077"&gt;@sivastat08&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I want to Add zero(0) in prefix wherever the length(&lt;STRONG&gt;Have&lt;/STRONG&gt;) less then “3” &amp;nbsp;and blank as blank.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;Have&lt;/TD&gt;
&lt;TD&gt;Length&lt;/TD&gt;
&lt;TD&gt;Want&lt;/TD&gt;
&lt;TD&gt;Length&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;112&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;TD&gt;112&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;12&lt;/TD&gt;
&lt;TD&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&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;TD&gt;1&lt;/TD&gt;
&lt;TD&gt;000&lt;/TD&gt;
&lt;TD&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;kindly help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Siva&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;How about SUBSTR on the left side of assignment statement equal sign.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data l0;
   infile cards missover;
   input Have $ Length1 xWant $ Length2;
   l = lengthn(have);
   if 0 eq l or l ge 3 then want = have;
   else do;
      want = '000';
      substr(want,3-l+1)=have;
      end;
   z = compare(xwant,want);
   cards;
112 3 112 3
12 2 012 3
12345 5 12345 5
cg.56 5 cg.56 5
87 2 087 3
1 1 001 3
112 3 112 3
1frt. 5 1frt. 5
   
e 1 00e 3
0 1 000 3
;;;;
   run;
proc print;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG title="Capture.PNG" alt="Capture.PNG" src="https://communities.sas.com/t5/image/serverpage/image-id/7597iB32B6415C0AD2855/image-size/original?v=1.0&amp;amp;px=-1" border="0" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 15:48:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338850#M77249</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2017-03-07T15:48:30Z</dc:date>
    </item>
    <item>
      <title>Re: Add (0) in prefix wherever the length less then “3”  for Character variable using sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338862#M77253</link>
      <description>&lt;P&gt;Simple substr() function will do it:&lt;/P&gt;
&lt;PRE&gt;data want;
  input have $;
  want=substr(cats("00",have),lengthn(cats("00",have))-2);
datalines;
112
12
1
;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Mar 2017 15:56:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338862#M77253</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-03-07T15:56:21Z</dc:date>
    </item>
    <item>
      <title>Re: Add (0) in prefix wherever the length less then “3”  for Character variable using sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338869#M77256</link>
      <description>Thanks for the replay.</description>
      <pubDate>Tue, 07 Mar 2017 16:01:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338869#M77256</guid>
      <dc:creator>sivastat08</dc:creator>
      <dc:date>2017-03-07T16:01:18Z</dc:date>
    </item>
    <item>
      <title>Re: Add (0) in prefix wherever the length less then “3”  for Character variable using sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338870#M77257</link>
      <description>Thanks for the replay.</description>
      <pubDate>Tue, 07 Mar 2017 16:01:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338870#M77257</guid>
      <dc:creator>sivastat08</dc:creator>
      <dc:date>2017-03-07T16:01:24Z</dc:date>
    </item>
    <item>
      <title>Re: Add (0) in prefix wherever the length less then “3”  for Character variable using sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338873#M77258</link>
      <description>Thanks for the result.</description>
      <pubDate>Tue, 07 Mar 2017 16:02:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338873#M77258</guid>
      <dc:creator>sivastat08</dc:creator>
      <dc:date>2017-03-07T16:02:25Z</dc:date>
    </item>
    <item>
      <title>Re: Add (0) in prefix wherever the length less then “3”  for Character variable using sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338874#M77259</link>
      <description>Thanks for the replay Mr.RW9.</description>
      <pubDate>Tue, 07 Mar 2017 16:03:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338874#M77259</guid>
      <dc:creator>sivastat08</dc:creator>
      <dc:date>2017-03-07T16:03:15Z</dc:date>
    </item>
    <item>
      <title>Re: Add (0) in prefix wherever the length less then “3”  for Character variable using sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338887#M77262</link>
      <description>&lt;P&gt;I would change your choice of solution to any one of the other solutions offered, since&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;'s proposed solution simply won't work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 16:22:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338887#M77262</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-07T16:22:41Z</dc:date>
    </item>
    <item>
      <title>Re: Add (0) in prefix wherever the length less then “3”  for Character variable using sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338890#M77264</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;If you want your solution to support strings longer than 3 characters then add a MIN() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  length have want $10;
  input have $;
  want=substr(cats('00',have),min(3,length(cats('00',have))-2));
  put have= want= ;
datalines;
112x
12
1
;;;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 16:34:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338890#M77264</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-03-07T16:34:03Z</dc:date>
    </item>
    <item>
      <title>Re: Add (0) in prefix wherever the length less then “3”  for Character variable using sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338893#M77266</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;, you are right, I havn't noticed that have can be short alphabetic. My mistake.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 16:52:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338893#M77266</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-03-07T16:52:17Z</dc:date>
    </item>
    <item>
      <title>Re: Add (0) in prefix wherever the length less then “3”  for Character variable using sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338954#M77275</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;, you are right, I havn't noticed that have can be short alphabetic. My mistake.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp;you could edit your reply to make it work for the OPs data.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 19:34:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338954#M77275</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2017-03-07T19:34:18Z</dc:date>
    </item>
    <item>
      <title>Re: Add (0) in prefix wherever the length less then “3”  for Character variable using sas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338977#M77287</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;, thanks.&lt;/P&gt;
&lt;P&gt;I have edited the post and fixed it.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Mar 2017 20:33:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Add-0-in-prefix-wherever-the-length-less-then-3-for-Character/m-p/338977#M77287</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2017-03-07T20:33:06Z</dc:date>
    </item>
  </channel>
</rss>

