Date: Fri, 16 Sep 2005 15:30:30 +0000
Reply-To: iw1junk@COMCAST.NET
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Ian Whitlock <iw1junk@COMCAST.NET>
Subject: Re: pre-pending zeros
vd4,
Assuming for SD2 you meant 3SD, and no internal blanks, try
data w ;
length y $ 3 ;
input x $char6. ;
y = translate(reverse(substr(reverse(trim(x)),1,3)),"0"," ") ;
cards ;
PAT
123456
23SD
000001
100000
22SSS1
13
7 7
;
Ian Whitlock
=================
Date: Fri, 16 Sep 2005 07:46:29 -0700
Reply-To: vd4@NJIT.EDU
Sender: "SAS(r) Discussion"
From: vd4@NJIT.EDU
Organization: http://groups.google.com
Subject: pre-pending zeros
Comments: To: sas-l
Content-Type: text/plain; charset="iso-8859-1"
Hi all
I got stuck in a situation.
There is a variable defined as character and the length of that
variable is 6.
Example:
PAT
123456
23SD
000001
100000
22SSS1
13
Now I want to take the last 3 character only and for that I can use the
substr.
but if the variable length is less than 3 then pre pend that with the
zeros.
so the output should look like this.
PAT
456
SD2
001
000
SS1
013
When I tried then I messed up at the numeric to character things and
preprnding zero don't work.
Thank you in the advance
|