BookmarkSubscribeRSS Feed
natanya
Calcite | Level 5
Hello,
I am using an ods html statement to move output from proc print into MS Excel. One variable is 5 digits, which is defined as character (created using put statement). When it moves to Excel, it reverts to numeric. Thus I loose any leading zeros. How can I retain the 5 digits as character in excel?
Thanks
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Suggest checking the forum archives, also the SAS support http://support.sas.com/ website for SAS-hosted DOC and supplemental technical / conference material.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

export excel retain leading zeros site:sas.com
Cynthia_sas
SAS Super FREQ
Hi:
As Scott suggests, searching the forum archives is a great idea, since there have been many previous forum postings on this topic. Basically, Excel does not respect SAS formats for leading zeroes -- even if the number is a character value in the SAS end of things, if Excel detects numbers, it applies a General number format to the cell which strips any leading zeroes. This is Microsoft behavior and the only way to impact the behavior is to send a Microsoft format from SAS to Excel.

You can either use a format to tell Excel that the number is a character variable or you can use a format to just put leading zeroes into the number. With HTML-based destinations, the HTMLSTYLE= style attribute is the way you would send a Microsoft format from SAS to Excel.

These two previous forum postings show how to use HTMLSTYLE:
http://support.sas.com/forums/thread.jspa?messageID=41019ꀻ
http://support.sas.com/forums/thread.jspa?messageID=8753∱

Do note that in SAS 9, you may want to use ODS MSOFFICE2K instead of ODS HTML -- because MSOFFICE2K uses Microsoft flavor of HTML tags and Excel is "happier" rendering those tags instead of ODS HTML tags which are HTML 4.0 tags (and Excel doesn't like those tags as well).

cynthia

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 904 views
  • 0 likes
  • 3 in conversation