LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (August 2011, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 25 Aug 2011 13:23:33 -0500
Reply-To:     Robin R High <rhigh@UNMC.EDU>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Robin R High <rhigh@UNMC.EDU>
Subject:      Re: Adding 0s in front of character variables
Comments: To: sas8832@HOTMAIL.CO.UK
In-Reply-To:  <201108251808.p7PAtrMG017138@willow.cc.uga.edu>
Content-Type: text/plain; charset="US-ASCII"

The REPEAT function works here:

* Add leading zeros to character variable;

data bb; input in $5. ; length out $5; out = CATT(REPEAT('0',4-length(in)),in); * 4, not 5; datalines; 5678 78 678 9 ;

proc print; run;

Obs in out

1 5678 05678 2 78 00078 3 678 00678 4 9 00009

Robin High UNMC

From: sas8832@HOTMAIL.CO.UK To: SAS-L@LISTSERV.UGA.EDU Date: 08/25/2011 01:12 PM Subject: Adding 0s in front of character variables Sent by: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>

Hello

I would a character id variable. I would like to add two 0s before a four digit id variable and one 0 before a five digit id variable. Any suggestions?

Thanks


Back to: Top of message | Previous page | Main SAS-L page