<?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: convert character value &amp;quot;1X11&amp;quot; to &amp;quot;000001X11&amp;quot; in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/convert-character-value-quot-1X11-quot-to-quot-000001X11-quot/m-p/683437#M207009</link>
    <description>&lt;P&gt;Two ways as a function result. First&lt;/P&gt;
&lt;PRE&gt;new = substr(repeat('0',8) || old, length(old)+10-max(length(old),9));
&lt;/PRE&gt;
&lt;P&gt;Second&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;way via IFC&lt;/P&gt;
&lt;PRE&gt;new = ifc ( length(old) &amp;gt; 9, old, cats(repeat('0',8-length(old)), old) );&lt;/PRE&gt;</description>
    <pubDate>Sat, 12 Sep 2020 13:43:52 GMT</pubDate>
    <dc:creator>RichardDeVen</dc:creator>
    <dc:date>2020-09-12T13:43:52Z</dc:date>
    <item>
      <title>convert character value "1X11" to "000001X11"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-value-quot-1X11-quot-to-quot-000001X11-quot/m-p/683372#M206975</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I expect to create 'new' variable from the 'old' variable.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;old&lt;/TD&gt;&lt;TD&gt;new&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;00163T10&lt;/TD&gt;&lt;TD&gt;000163T10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;755F10&lt;/TD&gt;&lt;TD&gt;000755F10&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;00846U12560&lt;/TD&gt;&lt;TD&gt;00846U12560&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1555&lt;/TD&gt;&lt;TD&gt;000001555&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;if the length of strings is less or equal than 9 then I expect to fill 0 to the front to make the length as 9, such as row 1,2, and 4.&lt;/P&gt;&lt;P&gt;if the length of strings is larger than 9 then I expect to ignore it, such as row 3.&lt;/P&gt;&lt;PRE&gt;data table1;
	infile cards truncover;
	input
	old $50.
	;
	cards;
00163T10
755F10
00846U12560
1555	
;;;;&lt;/PRE&gt;&lt;P&gt;Could you please give me some suggestions about this?&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2020 22:55:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-value-quot-1X11-quot-to-quot-000001X11-quot/m-p/683372#M206975</guid>
      <dc:creator>Alexxxxxxx</dc:creator>
      <dc:date>2020-09-11T22:55:32Z</dc:date>
    </item>
    <item>
      <title>Re: convert character value "1X11" to "000001X11"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-value-quot-1X11-quot-to-quot-000001X11-quot/m-p/683374#M206977</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262815"&gt;@Alexxxxxxx&lt;/a&gt;&amp;nbsp; Is this what you're looking for?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table1;
	infile cards truncover;
	input
	old $50.
	;
	cards;
00163T10
755F10
00846U12560
1555
;;;;

data want;
    set table1;
    new = strip(old);
    if length(new) &amp;lt; 9 then do;
        do until (length(new) = 9);
            new = '0'||new;
        end;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Sep 2020 23:15:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-value-quot-1X11-quot-to-quot-000001X11-quot/m-p/683374#M206977</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2020-09-11T23:15:42Z</dc:date>
    </item>
    <item>
      <title>Re: convert character value "1X11" to "000001X11"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-value-quot-1X11-quot-to-quot-000001X11-quot/m-p/683375#M206978</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262815"&gt;@Alexxxxxxx&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I expect to create 'new' variable from the 'old' variable.&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;old&lt;/TD&gt;
&lt;TD&gt;new&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;00163T10&lt;/TD&gt;
&lt;TD&gt;000163T10&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;755F10&lt;/TD&gt;
&lt;TD&gt;000755F10&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;00846U12560&lt;/TD&gt;
&lt;TD&gt;00846U12560&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1555&lt;/TD&gt;
&lt;TD&gt;000001555&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;if the length of strings is less or equal than 9 then I expect to fill 0 to the front to make the length as 9, such as row 1,2, and 4.&lt;/P&gt;
&lt;P&gt;if the length of strings is larger than 9 then I expect to ignore it, such as row 3.&lt;/P&gt;
&lt;PRE&gt;data table1;
	infile cards truncover;
	input
	old $50.
	;
	cards;
00163T10
755F10
00846U12560
1555	
;;;;&lt;/PRE&gt;
&lt;P&gt;Could you please give me some suggestions about this?&lt;/P&gt;
&lt;P&gt;Thanks in advance.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;One way:&lt;/P&gt;
&lt;PRE&gt;data table1;
	infile cards truncover;
	input
	old $50.
	;
   length new $ 50.;
   if length(old) le 9 then new=cats(repeat('0',8-length(old)),old);
   else new = old;
cards;
00163T10
755F10
00846U12560
1555	
;;;;
&lt;/PRE&gt;
&lt;P&gt;The Repeat function will repeat the string the number of times indicated. So if you "repeat" 0 one time the result is 00. So the calculation uses 8 instead of the likely more expected 9- length of the value. Length, if you weren't aware returns the number of used characters in a string which would include leading spaces if any. CATS combines string values stripping spaces.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Sep 2020 23:15:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-value-quot-1X11-quot-to-quot-000001X11-quot/m-p/683375#M206978</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-09-11T23:15:59Z</dc:date>
    </item>
    <item>
      <title>Re: convert character value "1X11" to "000001X11"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-value-quot-1X11-quot-to-quot-000001X11-quot/m-p/683377#M206979</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/262815"&gt;@Alexxxxxxx&lt;/a&gt;&amp;nbsp; &amp;nbsp;It's fairly straightforward&amp;nbsp;with PUT and TRANSLATE functions combo&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table1;
	infile cards truncover;
	input
	old $50.
	;
	cards;
00163T10
755F10
00846U12560
1555	
;;;;

data want;
 set table1;
 length need $50;
 if lengthn(old)&amp;lt;9 then need=translate(put(old,$9. -r),'0',' ');
 else need=old;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Sep 2020 23:24:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-value-quot-1X11-quot-to-quot-000001X11-quot/m-p/683377#M206979</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-09-11T23:24:36Z</dc:date>
    </item>
    <item>
      <title>Re: convert character value "1X11" to "000001X11"</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-character-value-quot-1X11-quot-to-quot-000001X11-quot/m-p/683437#M207009</link>
      <description>&lt;P&gt;Two ways as a function result. First&lt;/P&gt;
&lt;PRE&gt;new = substr(repeat('0',8) || old, length(old)+10-max(length(old),9));
&lt;/PRE&gt;
&lt;P&gt;Second&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;way via IFC&lt;/P&gt;
&lt;PRE&gt;new = ifc ( length(old) &amp;gt; 9, old, cats(repeat('0',8-length(old)), old) );&lt;/PRE&gt;</description>
      <pubDate>Sat, 12 Sep 2020 13:43:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-character-value-quot-1X11-quot-to-quot-000001X11-quot/m-p/683437#M207009</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-09-12T13:43:52Z</dc:date>
    </item>
  </channel>
</rss>

