<?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 Keeping leading zero in proc import multiple sheets in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Keeping-leading-zero-in-proc-import-multiple-sheets/m-p/955361#M373121</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am importing excel sheets into SAS but values with leading zero are missing when imported. How can I resolve this issue.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%macro dataload(sheet);
proc import out=work.&amp;amp;sheet
    datafile="S:\document\inpatient.xlsx"
    dbms=xlsx replace;
    sheet="&amp;amp;sheet";
    getnames=yes;
run;
%mend dataload;
%dataload(cbcs);
%dataload(vhi);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;For example, In excel 034567786 when imported will be 34567786. I can use data step&amp;nbsp; infile statement to import the file but i have 2 sheets. How can I import each sheets using the infile statement or how can I manipulate the proc import statement so that it keeps the leading zeros? Thanks&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Jan 2025 18:52:43 GMT</pubDate>
    <dc:creator>CathyVI</dc:creator>
    <dc:date>2025-01-07T18:52:43Z</dc:date>
    <item>
      <title>Keeping leading zero in proc import multiple sheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-leading-zero-in-proc-import-multiple-sheets/m-p/955361#M373121</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am importing excel sheets into SAS but values with leading zero are missing when imported. How can I resolve this issue.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;%macro dataload(sheet);
proc import out=work.&amp;amp;sheet
    datafile="S:\document\inpatient.xlsx"
    dbms=xlsx replace;
    sheet="&amp;amp;sheet";
    getnames=yes;
run;
%mend dataload;
%dataload(cbcs);
%dataload(vhi);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;For example, In excel 034567786 when imported will be 34567786. I can use data step&amp;nbsp; infile statement to import the file but i have 2 sheets. How can I import each sheets using the infile statement or how can I manipulate the proc import statement so that it keeps the leading zeros? Thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2025 18:52:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-leading-zero-in-proc-import-multiple-sheets/m-p/955361#M373121</guid>
      <dc:creator>CathyVI</dc:creator>
      <dc:date>2025-01-07T18:52:43Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping leading zero in proc import multiple sheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-leading-zero-in-proc-import-multiple-sheets/m-p/955362#M373122</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/253321"&gt;@CathyVI&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I am importing excel sheets into SAS but values with leading zero are missing when imported. How can I resolve this issue.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;%macro dataload(sheet);
proc import out=work.&amp;amp;sheet
    datafile="S:\document\inpatient.xlsx"
    dbms=xlsx replace;
    sheet="&amp;amp;sheet";
    getnames=yes;
run;
%mend dataload;
%dataload(cbcs);
%dataload(vhi);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;For example, In excel 034567786 when imported will be 34567786. I can use data step&amp;nbsp; infile statement to import the file but i have 2 sheets. How can I import each sheets using the infile statement or how can I manipulate the proc import statement so that it keeps the leading zeros? Thanks&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If any of the cells in the column in the XLSX worksheet contain text values then the variable in SAS will be character.&amp;nbsp; So if the cell contained the string&amp;nbsp;034567786 then the leading zero will be preserved.&amp;nbsp; But if the cell contained the number&amp;nbsp;34,567,786 instead but had Excel formatting attached to display it as that 9 digit string then the leading zero will not come over.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if all of the cells in the column in the XLSX worksheet is NUMERIC then the variable in SAS will be NUMERIC also.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To print the number&amp;nbsp;34,567,786 as the string&amp;nbsp;034567786 attach the Z9. format specification to the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if the variable in SAS is numeric than add a FORMAT statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  format myvar z9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And if the variable in SAS is character then you need to first make sure it has a length of at least 9 and then convert the digit string back into a number using the INPUT() function which you can then convert back into a string using the PUT() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   length myvar $9;
   set have;
   myvar = put(input(myvar,32.),Z9.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want something that works in both cases then make a NEW variable.&amp;nbsp; Probably a character one since you want the leading zeros to be significant.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have(rename=(myvar=old_myvar));
  myvar = put(input(cats(old_myvar),32.),z9.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Not sure what you mean by data step and infile. You cannot read XLSX files that way.&amp;nbsp; But if you have CSV files then you can. (Note that CSV files are NOT Excel files, just plain old TEXT files, even if your PC tries to open them automatically with Excel).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to convert an XLSX file with multiple sheets into a CSV file then you will need a separate CSV file for each sheet.&amp;nbsp; You could store them both into a ZIP if you wanted to share them as a single file.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2025 19:12:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-leading-zero-in-proc-import-multiple-sheets/m-p/955362#M373122</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-01-07T19:12:14Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping leading zero in proc import multiple sheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-leading-zero-in-proc-import-multiple-sheets/m-p/955380#M373129</link>
      <description>&lt;P&gt;The only method I have had any luck with maintaining Excel values is to export the sheets to CSV file(s) and then use a data step to read the resulting files setting the values that Excel likely had as numeric as character to maintain the leading 0 in SAS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the sheets have the same structure then read the separate files by changing the infile file name and the Data set created.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2025 20:05:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-leading-zero-in-proc-import-multiple-sheets/m-p/955380#M373129</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2025-01-07T20:05:10Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping leading zero in proc import multiple sheets</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-leading-zero-in-proc-import-multiple-sheets/m-p/955441#M373137</link>
      <description>&lt;P&gt;You can import these columns/variables of Excel as CHARACTER variables to retain those leading zero.&lt;/P&gt;
&lt;P&gt;1) the first way is using PROC IMPORT:&lt;/P&gt;
&lt;PRE&gt;proc import datafile = "c:\temp\date.xlsx" out =have replace dbms =excel ;
dbdsopts="dbsastype=(age='numeric' &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;weight='char(20)'&lt;/STRONG&gt; &lt;/FONT&gt;)";
run;&lt;/PRE&gt;
&lt;P&gt;2) the second way is using LIBNAME:&lt;/P&gt;
&lt;PRE&gt;libname x excel 'c:\temp\date.xlsx';
data have2;
set x.'date$'n(dbsastype=(age='numeric' &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;weight='char(20)'&lt;/STRONG&gt;&lt;/FONT&gt;));
run;
&lt;/PRE&gt;</description>
      <pubDate>Wed, 08 Jan 2025 01:40:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-leading-zero-in-proc-import-multiple-sheets/m-p/955441#M373137</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-01-08T01:40:21Z</dc:date>
    </item>
  </channel>
</rss>

