Hello
In following code the data in excel doesn't includes leading zeros.
What is the way to solve it?
Why option leading_zero="yes" is not working?
data one;
retain zip account;
set sashelp.class;
zip="06555";
account="0345";
run;
ods msoffice2k path="path" (url=none)
gpath="pathr" (url=none)
file="file4b.xls"
options( leading_zero="yes")
style=normal;
proc print data=one noobs;
Title;
var zip account;
var age height / style(data)={htmlstyle="mso-number-format:'##.00'"};
var weight;
run;
ods msoffice2k close;
First of all: don't lie with your filename extension. ODS MSOFFICE2K creates HTML, so the file should have an extension of .html or .htm.
When you look at the file, you'll see that you get a HTML TABLE object. HTML TABLE cells do not have a type, so Excel has to guess what it is. 06555 looks like a number, Excel stores it as such, and uses the default number format which suppresses leading zeroes. The only things that are recognized are the alignment (because that's part of the HTML TABLE cell formatting), and the mso-number-format style property.
Stop mixing file types and old syntax. If you want to create an actual Excel file for the modern day, then it will be an XLSX formatted file created using ods Excel. What you are creating there is HTML. Then you are calling it XLS, which it is not, and you wouldn't want an old file format like XLS which is proprietary binary file replaced now by the Open Office file format such as XLSX.
Ods excel:
https://support.sas.com/resources/papers/proceedings17/0169-2017.pdf
If you don't have the latest SAS version (and the question then is why not?), then use ods tagsets.excelxp. This creates XML output which Excel can parse:
https://support.sas.com/resources/papers/proceedings17/0973-2017.pdf
That doesn't create native files though, just xml which is not ideal, but does have a lot of formatting options.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.