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
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