<?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 pad  character variables with values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-pad-character-variables-with-values/m-p/468406#M119628</link>
    <description>&lt;P&gt;I forgot to mention that some values can be&lt;/P&gt;&lt;P&gt;11-000-abcd1 , so this is not a numeric variable.&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
    <pubDate>Thu, 07 Jun 2018 15:08:38 GMT</pubDate>
    <dc:creator>Rigler</dc:creator>
    <dc:date>2018-06-07T15:08:38Z</dc:date>
    <item>
      <title>how to pad  character variables with values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-pad-character-variables-with-values/m-p/468382#M119621</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello ,&lt;/P&gt;&lt;P&gt;I have a large dataset where I&amp;nbsp; need to add leading&amp;nbsp;number to some of the variables. here is a subset of the data&lt;/P&gt;&lt;P&gt;Data&amp;nbsp; have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11-000-0067&lt;BR /&gt;5511-000-00267&lt;BR /&gt;5511-000-00367&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 11-000-01166&lt;BR /&gt;5511-000-11166&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I want to add&amp;nbsp; 55 to those that are missing the leading number to get the following result&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;5511-000-00671&lt;BR /&gt;5511-000-00267&lt;BR /&gt;5511-000-00367&lt;BR /&gt;5511-000-01166&lt;BR /&gt;5511-000-11166&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jun 2018 14:30:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-pad-character-variables-with-values/m-p/468382#M119621</guid>
      <dc:creator>Rigler</dc:creator>
      <dc:date>2018-06-07T14:30:48Z</dc:date>
    </item>
    <item>
      <title>Re: how to pad  character variables with values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-pad-character-variables-with-values/m-p/468390#M119623</link>
      <description>&lt;P&gt;Is it always 55 in front, and 1 at end?&amp;nbsp; I would do something like:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  length want want1 want2 want3 $50;
  if lengthn(scan(have,1,"-")) ne 4 then want1=cats(repeat("5",4-lengthn(scan(have,1,"-")),scan(have,1,"-"));
  else want1=scan(have,1,"-");
  ...
  want=catx('-',want1--want3);
run;
&lt;/PRE&gt;
&lt;P&gt;Ie break the string up into three, check the length, padd as needed, then cat together.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jun 2018 14:38:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-pad-character-variables-with-values/m-p/468390#M119623</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-06-07T14:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: how to pad  character variables with values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-pad-character-variables-with-values/m-p/468391#M119624</link>
      <description>&lt;P&gt;Did you miss "1" in your first records for the data you have?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input num $15.;
datalines;
11-000-00671
5511-000-00267
5511-000-00367
11-000-01166
5511-000-11166
;
run;
data want;
set have;
if length(num)=12 then num=cats("55",num);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Jun 2018 14:38:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-pad-character-variables-with-values/m-p/468391#M119624</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-06-07T14:38:49Z</dc:date>
    </item>
    <item>
      <title>Re: how to pad  character variables with values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-pad-character-variables-with-values/m-p/468392#M119625</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input number:$20.;
cards;
11-000-00671
5511-000-00267
5511-000-00367
11-000-01166
5511-000-11166
;

data want;
  set have;
  length number2 $20.;
  number2 = tranwrd(put(number, 14.-R),' ','5'); 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 07 Jun 2018 14:39:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-pad-character-variables-with-values/m-p/468392#M119625</guid>
      <dc:creator>amatsu</dc:creator>
      <dc:date>2018-06-07T14:39:04Z</dc:date>
    </item>
    <item>
      <title>Re: how to pad  character variables with values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-pad-character-variables-with-values/m-p/468406#M119628</link>
      <description>&lt;P&gt;I forgot to mention that some values can be&lt;/P&gt;&lt;P&gt;11-000-abcd1 , so this is not a numeric variable.&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jun 2018 15:08:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-pad-character-variables-with-values/m-p/468406#M119628</guid>
      <dc:creator>Rigler</dc:creator>
      <dc:date>2018-06-07T15:08:38Z</dc:date>
    </item>
    <item>
      <title>Re: how to pad  character variables with values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-pad-character-variables-with-values/m-p/468409#M119629</link>
      <description>&lt;P&gt;this code does not seem to work for me. Please note this is a character variable,&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jun 2018 15:20:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-pad-character-variables-with-values/m-p/468409#M119629</guid>
      <dc:creator>Rigler</dc:creator>
      <dc:date>2018-06-07T15:20:42Z</dc:date>
    </item>
    <item>
      <title>Re: how to pad  character variables with values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-pad-character-variables-with-values/m-p/468415#M119633</link>
      <description>&lt;P&gt;Please show what you get in output.&lt;/P&gt;
&lt;P&gt;Check if leading or trailing blanks are causing the issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;length&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;num&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;12&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; num&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;cats&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"55"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,strip(&lt;/SPAN&gt;num)&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jun 2018 15:34:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-pad-character-variables-with-values/m-p/468415#M119633</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-06-07T15:34:59Z</dc:date>
    </item>
    <item>
      <title>Re: how to pad  character variables with values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-pad-character-variables-with-values/m-p/468442#M119649</link>
      <description>&lt;P&gt;Assuming that you have a character variable that might contain exactly&amp;nbsp;two leading blanks:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;if (var &amp;gt; ' ') and (var =: '&amp;nbsp; ') then substr(var, 1, 2)&amp;nbsp;= '55';&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The assumptions about what is in the data are critical, however, and this only works if the assumptions are correct.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jun 2018 16:20:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-pad-character-variables-with-values/m-p/468442#M119649</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-06-07T16:20:59Z</dc:date>
    </item>
    <item>
      <title>Re: how to pad  character variables with values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-pad-character-variables-with-values/m-p/468500#M119673</link>
      <description>&lt;P&gt;After another try, this works perfectly.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much!&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jun 2018 19:22:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-pad-character-variables-with-values/m-p/468500#M119673</guid>
      <dc:creator>Rigler</dc:creator>
      <dc:date>2018-06-07T19:22:13Z</dc:date>
    </item>
  </channel>
</rss>

