<?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 multiple numeric variables to character with leading zeros in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/convert-multiple-numeric-variables-to-character-with-leading/m-p/496091#M131105</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input date date9. cust_id_1 cust_id_2 cust_id_3 cust_id_4 cust_id_5 cust_id_6;
datalines;
01SEP2018 1458976 768976 9856786 7634543 494756 6578436
10SEP2018 859034 7689543 214987 7639856 5674849 35467869
11SEP2018 1254679 1615432 165908 6752143 190876 1098723
;
RUN;

data _null_;
set have;
array t(*) cust_id_:;
call symputx('n',dim(t));
stop;
run;



%put &amp;amp;n;

data want;
set have;
array t  cust_id_:;
array cust_id_new(&amp;amp;n) $15;
do _i_=1 to dim(t);
cust_id_new(_i_)=put(t(_i_),z11.);
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 17 Sep 2018 00:16:53 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-09-17T00:16:53Z</dc:date>
    <item>
      <title>convert multiple numeric variables to character with leading zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-multiple-numeric-variables-to-character-with-leading/m-p/496088#M131103</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the below dataset with multiple customer ids in numeric format. I need to convert them to character variables with leading zeros with 11 character length. How can I do that in a single step for multiple variables?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;input date date9. cust_id_1 cust_id_2 cust_id_3 cust_id_4 cust_id_5 cust_id_6;&lt;BR /&gt;datalines;&lt;BR /&gt;01SEP2018 1458976 768976 9856786 7634543 494756 6578436&lt;BR /&gt;10SEP2018 859034 7689543 214987 7639856 5674849 35467869&lt;BR /&gt;11SEP2018 1254679 1615432 165908 6752143 190876 1098723&lt;BR /&gt;;&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;The final dataset should look as below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;date &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cust_id_1 &amp;nbsp; &amp;nbsp; cust_id_2 &amp;nbsp; &amp;nbsp; &amp;nbsp; cust_id_3 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp; cust_id_4 &amp;nbsp; &amp;nbsp; &amp;nbsp; cust_id_5 &amp;nbsp; &amp;nbsp; &amp;nbsp; cust_id_6&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;01SEP2018 00001458976 00000768976 00009856786 00007634543 00000494756 00006578436&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;10SEP2018 00000859034 00007689543 00000214987 00007639856 00005674849 00035467869&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;11SEP2018 00001254679 00001615432 00000165908 00006752143 00000190876 00001098723&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 00:06:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-multiple-numeric-variables-to-character-with-leading/m-p/496088#M131103</guid>
      <dc:creator>nickspencer</dc:creator>
      <dc:date>2018-09-17T00:06:01Z</dc:date>
    </item>
    <item>
      <title>Re: convert multiple numeric variables to character with leading zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-multiple-numeric-variables-to-character-with-leading/m-p/496090#M131104</link>
      <description>&lt;P&gt;This is an untested&amp;nbsp; code but should work&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input date date9. cust_id_1 cust_id_2 cust_id_3 cust_id_4 cust_id_5 cust_id_6;
datalines;
01SEP2018 1458976 768976 9856786 7634543 494756 6578436
10SEP2018 859034 7689543 214987 7639856 5674849 35467869
11SEP2018 1254679 1615432 165908 6752143 190876 1098723
;
RUN;

data want;
set have;
array charn(6) cust_id_1 cust_id_2 cust_id_3 cust_id_4 cust_id_5 cust_id_6;
array charc(6) $12. id1-id6;
do i = 1 to 6;
charc(i)=put(charn(i),z11.);
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 00:11:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-multiple-numeric-variables-to-character-with-leading/m-p/496090#M131104</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2018-09-17T00:11:29Z</dc:date>
    </item>
    <item>
      <title>Re: convert multiple numeric variables to character with leading zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-multiple-numeric-variables-to-character-with-leading/m-p/496091#M131105</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input date date9. cust_id_1 cust_id_2 cust_id_3 cust_id_4 cust_id_5 cust_id_6;
datalines;
01SEP2018 1458976 768976 9856786 7634543 494756 6578436
10SEP2018 859034 7689543 214987 7639856 5674849 35467869
11SEP2018 1254679 1615432 165908 6752143 190876 1098723
;
RUN;

data _null_;
set have;
array t(*) cust_id_:;
call symputx('n',dim(t));
stop;
run;



%put &amp;amp;n;

data want;
set have;
array t  cust_id_:;
array cust_id_new(&amp;amp;n) $15;
do _i_=1 to dim(t);
cust_id_new(_i_)=put(t(_i_),z11.);
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Sep 2018 00:16:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-multiple-numeric-variables-to-character-with-leading/m-p/496091#M131105</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-17T00:16:53Z</dc:date>
    </item>
    <item>
      <title>Re: convert multiple numeric variables to character with leading zeros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/convert-multiple-numeric-variables-to-character-with-leading/m-p/496092#M131106</link>
      <description>&lt;P&gt;Use sashelp.vcolumn to feed a data step which creates the conversion step with call execute:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set sashelp.vcolumn end=eof (where=(libname = "WORK" and memname = "HAVE" and substr(upcase(name),1,4) = "CUST"));
if _n_ = 1 then call execute("data want; set have;");
call execute('_' !! name !! '= put(' !! name !! ',z11.);');
call execute('drop ' !! name !! ';');
call execute('rename _' !! name !! '=' !! name !! ';');
if eof then call execute('run;');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Sep 2018 00:22:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/convert-multiple-numeric-variables-to-character-with-leading/m-p/496092#M131106</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-17T00:22:25Z</dc:date>
    </item>
  </channel>
</rss>

