Date: Thu, 28 Oct 2004 08:35:43 -0500
Reply-To: "Dunn, Toby" <Toby.Dunn@TEA.STATE.TX.US>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Dunn, Toby" <Toby.Dunn@TEA.STATE.TX.US>
Subject: Re: re-ordering characters in a varible
Content-Type: text/plain; charset="us-ascii"
Nevin,
AS general solution to were you don't have to worrie about what place
the character is in the value, or how many numbers verses characters you
have try the following:
data one;
input code $6.;
cards;
2065a
2065AB
2045BA
20677A
;
run;
%let alpha = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz';
%let beta = '1234567890';
data two;
set one;
code = compress(substr(reverse(code),1,(indexc(reverse(code),&beta)-1))
||
substr(code,1,(indexc(code,&alpha)-1)));
put code=;
run;
HTH
Toby Dunn
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
Nevin Krishna
Sent: Wednesday, October 27, 2004 4:48 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: re-ordering characters in a varible
Hello All,
Suppose you have a variable (character) called "code" and that this
variable has the following appearance in a dataset:
code
2065A
2045B
2067A
now suppose you want to modify this variable so that the order is
changed and the letter appears first such as:
code
A2065
B2045
A2067
I have accomplished this already by creating two separate variables (one
for the letter and one for the numbers), and then combining them using
|| in the new order i want.. However i am looking for a simple way of
doing this without having to create new variables...any idea?
Thanks, Nevin
|