Sample 48547: Prevent the loss of leading zeros with the ODS CSV destination
Generating CSV files and viewing them in Excel might display some fields in undesirable formats. This occurs because Excel uses the General format when the CSV file is opened or imported into Excel. This causes the loss of leading zeros from displaying, even though the leading zero is a part of the data value. If you are using the ODS CSV destination to generate the CSV file, you can use a combination of the PREPEND_EQUALS="yes" option along with the QUOTE_BY_TYPE="yes" ODS CSV option, which quotes the value and prepends the "=" to the value.
This simulates the TEXT format and preserves the leading zeros. Other ODS destinations, such as the MSOffice2K and the ExcelXP destinations, have the ability to pass Excel formats within the destination. See SAS Note 38105 for more information.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
/* Sample DATA step to create a variable with leading zeros */
/* that are not displayed in Excel. */
data one;
leading="00001";
run;
/* Add the options so that the leading zero displays */
ods csv file="c:\temp.csv" options(prepend_equals="yes"
quote_by_type="yes");
proc print data=one;
run;
ods csv close;
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This sample illustrates how to prevent the loss of leading zeros when generating output with the ODS CSV destination.
| Date Modified: | 2012-12-07 15:51:59 |
| Date Created: | 2012-11-28 10:32:39 |
Operating System and Release Information
| SAS System | Base SAS | z/OS | 9.2 TS1M0 | |
| Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.2 TS1M0 | |
| Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.2 TS1M0 | |
| Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.2 TS1M0 | |
| Microsoft Windows XP 64-bit Edition | 9.2 TS1M0 | |
| Microsoft® Windows® for x64 | 9.2 TS1M0 | |
| Microsoft Windows Server 2003 Datacenter Edition | 9.2 TS1M0 | |
| Microsoft Windows Server 2003 Enterprise Edition | 9.2 TS1M0 | |
| Microsoft Windows Server 2003 Standard Edition | 9.2 TS1M0 | |
| Microsoft Windows XP Professional | 9.2 TS1M0 | |
| Windows Vista | 9.2 TS1M0 | |
| Windows Vista for x64 | 9.2 TS1M0 | |
| 64-bit Enabled AIX | 9.2 TS1M0 | |
| 64-bit Enabled HP-UX | 9.2 TS1M0 | |
| 64-bit Enabled Solaris | 9.2 TS1M0 | |
| HP-UX IPF | 9.2 TS1M0 | |
| Linux | 9.2 TS1M0 | |
| Linux for x64 | 9.2 TS1M0 | |
| OpenVMS on HP Integrity | 9.2 TS1M0 | |
| Solaris for x64 | 9.2 TS1M0 | |