DATA Step, Macro, Functions and more

Zipcode issue

Reply
Super Contributor
Posts: 673

Zipcode issue

Excel truncates any leading zeros.But some of the zip codes start with a zero, so in SAS we will have zipcodes with missing leading zeros.Is there any function that adds required number of zeros to the zip code.I will have a 5 digit zipcode.
Frequent Contributor
Posts: 102

Re: Zipcode issue

If you are storing it in SAS as a number, you can display it with leading zeros using the z5. format (In Excel, you can use an Excel format to display ZIP codes with leading zeros).

If you are storing the number in a 5-byte character field in SAS, you could put the zeros back with the translate function (first make sure the remaining digits are right-justified).
Super Contributor
Super Contributor
Posts: 3,174

Re: Zipcode issue

Posted in reply to JackHamilton
If you have a combination of zip_code and zip+4 values, you will need to store the string as character, and for instances where there is no dash, use the PUT function and the Z5. format as mentioned to create the SAS CHARACTER variable $10, otherwise you should already have a ten-digit string since it will not be converted by Excel.

Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 2 replies
  • 2185 views
  • 0 likes
  • 3 in conversation