Technoleros

Observations from hacking around with all kinds of hardware and software

  • Home
  • Downloads
RSS

Add Leading Zeroes to SAS Data

Posted on October 6, 2009 by Fred Janssen
No commentsLeave a comment

saslogo You probably have many SAS data sets that you regularly work with where numbers are stored as text for formatting purposes.  A great example is the social security number, and many other customer, product, or invoice numbers are formatted similarly.  They frequently utilize leading zeros in their storage and display.  You probably also frequently receive data from colleagues where the same variable is formatted as a numeric value missing the leading zeros.  The join that you were going to do with your data and the data received from the colleague just won’t work.  Here is a little SAS code that can turn your colleague’s data into a match for yours, and I’ll use social security number (SSN) in this example:

data DatasetName ;
set InputDataset ;
length ssn_char $9. /* New Character var for SSN                    */
ssn_char = put(ssn,z9.) ; /* Put the Numeric SSN with the Z9. format   */
drop ssn ; /* Housecleaning to drop the numeric SSN    */
rename ssn_char = ssn ; /* Renamed Char SSN to make our Join easier */
run ;

By creating a new Character variable of SSN, I can simply put the Numeric SSN with Z9. format into the variable.

The format Z9. states the variable should be 9-bytes, and for each byte less than 9, put a leading zero in front of the var.

No strip or trim is necessary either.

I used this in the past with a transaction number I was creating (numeric) and later wanted to display it in a title with leading zeros [Example:  had 123 as the value, put it with a Z10. and the display in the title was 0000000123].

Thanks to Paula for showing me this trick!
Be Sociable, Share!
  • Tweet
Categories: Business Intelligence, Data, Software, Statistics | Tags: SAS
Notice: This work is licensed under a BY-NC-SA. Permalink: Add Leading Zeroes to SAS Data
Upgrading to SAS 9.2: SAS Enterprise Guide 4.2
SAS OLAP Server Names

Leave a Reply Cancel reply

You must be logged in to post a comment.

  • Categories

    Biking Business Intelligence Data Downloads GIS GPS Hardware Maps Media Outdoors PDA Smartphone Software Statistics Technology Twitter Uncategorized Web

  • Tags

    analysis ArcGIS ArcPad ArcView attributes Austin BaseCamp browser Communicator coordinates elevation Enterprise Guide ESRI extension firmware Garmin geocaching geography geotagging Google GPS health hot fix Junction kml Maps MapSource mobile NOAA OLAP projection registry routes SAS satellite scripts toolbox topography tracks transfer utility waypoints Web Report Studio Webupdater Windows
  • Meta

    • Register
    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
  • Recommended Links

    • Ed Bott’s Windows Expertise
    • Engadget
    • Free Geography Tools
    • Geocaching
    • Hardware 2.0
    • Lifehacker
    • MapMyRide
    • sasCommunity.org
    • the SAS BI-ogsource
    • Trails.com
  • Recent Tweets...

    • SAS Global Forum registration now OPEN! - http://t.co/6JjZXcth 2011-11-13
    • Flash is dead. Long live HTML5. http://t.co/sgKYHr0Y 2011-11-10
    • How to create multiple LSF users - http://t.co/va4rbPcv #SAS 2011-11-04
    • Adding WRS to Portal in #SAS 9.2 / 9.3 - http://t.co/pYU9gdYv 2011-11-04
    • CSR announces SiRFstarV chipset - http://t.co/D3fAgsPa 2011-11-04
    • Kinect for Windows is Confirmed for 2012- http://t.co/sVGZhexJ 2011-11-04
    • Using Windows PowerShell to report on your #SAS Enterprise Guide project files - http://t.co/kitxR3Ic 2011-11-04
    • New #SAS Job Site - http://t.co/IkcxaTm9 2011-11-04
    • How To Install Windows 8 From A USB Flash Drive - http://t.co/10A8dF4u 2011-11-04
    • GarageBand 1.1 available for iPhone and iPod touch users - http://t.co/7211B6EJ 2011-11-04
    • More updates...

    Posting tweet...

© Technoleros. Proudly Powered by WordPress | Nest Theme by YChong