Date: Thu, 21 Nov 2002 11:28:06 GMT
Reply-To: Fraser Neiman <fn9r@VIRGINIA.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Fraser Neiman <fn9r@VIRGINIA.EDU>
Organization: University of Virginia
Subject: Re: character string parsing
Thanks to everyone for their suggestions. All but one foundered
on the case where the value is all numeric - i.e. changed 752
in my example to 75. Values that have only numeric characters
need to stay unchanged. Here is some code sent by Roger Lustig
that does the trick:
****************** Numerics only;
if indexc(context,'ABCDEFGHIJKLMNOPQRSTUVWXYZ') =0 then context2=context;
****************** Last character is alpha;
else if indexc(left(reverse(context)),'01234567890') ne 1 then
context2=context;
****************** Last character is numeric;
else context2=substr(context,1,length(context)-1);
Thanks again!
Best, Fraser
Fraser Neiman <fn9r@Virginia.EDU> wrote:
: Hi Folks,
: I have a simple character string parsing problem that I am too
: simple to solve. I have a character variable called context
: whose values consist of a string of numbers, sometimes followed by some
: letters, and then sometimes followed a single number. I need to
: some code that will identify those cases where the right most
: character is a number and then output all the numbers and
: characters to left. So for example, 746AD1 would become 746AD;
: 752B2 would become 752B; 752 would be left unchanged. Ive
: appended a listing of typical context values.
: Thanks for any help.
: Best, Fraser
: context
: 792B
: 736D
: 736E
: 792C1
: 746AD1
: 753C
: 785AA2
: 779AC2
: 764AA3
: 753AA3
: 737TPS
: 764AB2
: 746AB1
: 746AB2
: 746AC1
: 746AC3
: 746AC4
: 746AD3
: 746AD4
: 796AA1
: 796AA2
: 796AB2
: 752B2
: 752C5
: 752
: 752AA1
: 752AA2
: 752AA3
: 752AA4
: 752AB1
|