Date: Wed, 4 Feb 2009 15:37:22 -0500
Reply-To: Jack Clark <jclark@HILLTOP.UMBC.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jack Clark <jclark@HILLTOP.UMBC.EDU>
Subject: Re: Find position of last occurrence of character in a string
In-Reply-To: <62432006F5965C42BAEC4EA29286EE0507B4DABC0C@EX-CMS01.westat.com>
Content-Type: text/plain; charset="us-ascii"
Sig,
Thank you for pointing out the shortcoming of my original response. My
fingers were moving quicker than my mind.
I think that the combination of INDEX and REVERSE functions can be used
to find the last occurrence of a character in a string. Something like
the following may work.
data _null_;
var1 = "abc/abc/abc/ 333";
rev_idx = length(var1) - index(reverse(var1),"/") + 1;
put var1= rev_idx=;
run;
Jack Clark
Senior Research Analyst
phone: 410-455-6256
fax: 410-455-6850
jclark@hilltop.umbc.edu -----Original Message-----
From: Sigurd Hermansen [mailto:HERMANS1@WESTAT.com]
Sent: Wednesday, February 04, 2009 3:20 PM
To: Jack Clark
Subject: RE: Find position of last occurrence of character in a string
Jack:
Wouldn't one have to reverse the search string as well?
S
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
Jack Clark
Sent: Wednesday, February 04, 2009 3:07 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Find position of last occurrence of character in a string
JDB,
You could always use the REVERSE function on the string first, then the
INDEX function.
Jack Clark
Senior Research Analyst
phone: 410-455-6256
fax: 410-455-6850
jclark@hilltop.umbc.edu
University of Maryland, Baltimore County
Sondheim Hall, 3rd Floor
1000 Hilltop Circle
Baltimore, MD 21250
Confidentiality Notice: This e-mail may contain information that is
legally privileged and that is intended only for the use of the
addressee(s) named above. If you are not the intended recipient, you are
hereby notified that any disclosure, copying of this e-mail,
distribution, or action taken in reliance on the contents of this e-mail
and/or documents attributed to this e-mail is strictly prohibited. If
you have received this information in error, please notify the sender
immediately by phone and delete this entire e-mail. Thank
you.-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of JDB
Sent: Wednesday, February 04, 2009 2:59 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Find position of last occurrence of character in a string
I am looking for a function that will allow me to find the position of
the last occurrence of a specific character in a string. Basically the
opposite of the index function. For example if I wanted to find the
position of the last "/" in the following string "abc/abc/abc/ 333". I
will not know how many "/" will appear before the last occurrence.
Thanks