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 (December 2008, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Wed, 10 Dec 2008 11:20:19 -0600
Reply-To:   Joe Matise <snoopy369@GMAIL.COM>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Joe Matise <snoopy369@GMAIL.COM>
Subject:   Re: Removing characters using prxchange
In-Reply-To:   <200812101653.mBAG4XLs032546@malibu.cc.uga.edu>
Content-Type:   text/plain; charset=ISO-8859-1

You should be able to do this, I think:

data have; infile datalines dsd missover; input code: $; datalines; AB 237 AB 248A CD 239 CC3 CD A48 AB 225 B AB 225 #1 AB225 ; run;

data want; set have; code2 = prxchange('s/([A-Z]{2}) ?(\d{3}).*/$1 $2/',-1,code); run; -Joe

On Wed, Dec 10, 2008 at 10:53 AM, Sid N <nsid31@gmail.com> wrote:

> Hi, > > I am trying to use perl regular expressions to change/remove characters > from > my dataset, but have not been very successful. The sample data is provided > below: > > data have; > infile datalines dsd missover; > input code: $; > datalines; > AB 237 > AB 248A > CD 239 CC3 > CD A48 > AB 225 B > AB 225 #1 > AB225 > ; > run; > > I would like to remove characters based on the following conditions: > 1. Remove the last character along with any leading spaces if the last > character is a letter (as in AB 248A and AB 225 B). Desired output is AB > 248 > and AB 225. > 2. Remove any characters following a special character (along with the > special character -- AB 225 #1). Desired output is AB 225. > 3. Remove all characters beginning with the second set of alpha characters > (CD 239 CC3 to CD 239). > > The final output I am looking for is: > AB 237 > AB 248 > CD 239 > CD A48 > AB 225 > AB 225 > AB225 > > Please note there are no space(s) in some values (example: AB225). > > Thanks in advance. > Sid >


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