LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (November 2002, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Wed, 20 Nov 2002 17:41:28 -0500
Reply-To:   Bob Burnham <robert.a.burnham@DARTMOUTH.EDU>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Bob Burnham <robert.a.burnham@DARTMOUTH.EDU>
Organization:   Dartmouth College, Hanover, NH, USA
Subject:   Re: character string parsing
Content-Type:   text/plain; charset=us-ascii

Fraser Neiman <fn9r@Virginia.EDU> writes:

+---------------------------------------------------------------- | So for example, 746AD1 would become 746AD; 752B2 would become | 752B; 752 would be left unchanged. Ive appended a listing of | typical context values. +----------------------------------------------------------------

Fraser,

Try something like this:

data test (drop=c); input context $; c = substr(context, length(context), 1); if (indexc(c, "0123456789") > 0) then newcontext = substr(context, 1, length(context) - 1); else newcontext = context; datalines; 792B 736D 736E 792C1 746AD1 753C etc.

It should produce output something like this:

context newcontext

792B 792B 736D 736D 736E 736E 792C1 792C 746AD1 746AD 753C 753C 785AA2 785AA 779AC2 779AC 764AA3 764AA 753AA3 753AA 737TPS 737TPS

You can combine several of the lines into one statement and avoid using the temporary 'c' variable -- but I think it might clearer this way.

Hope this helps,

Bob

-- Bob Burnham robert.a.burnham@dartmouth.edu http://www.dartmouth.edu/~bburnham


Back to: Top of message | Previous page | Main SAS-L page