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 (September 2010, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 13 Sep 2010 07:29:50 -0400
Reply-To:     Søren Lassen <s.lassen@POST.TELE.DK>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Søren Lassen <s.lassen@POST.TELE.DK>
Subject:      Re: A Character value manupulation problem - please help
Comments: To: Tom Smith <need_sas_help@YAHOO.COM>
Content-Type: text/plain; charset=ISO-8859-1

Tom, A couple of solutions have already been suggested, but you may want to take into account cases where the words "Ghe" or "sw" occur in the beginning of the string or at the very end, e.g. data have; infile cards truncover; input SDE $40.; cards; 10 after after End Of sw infusion 5 minute After end OF sw infusion 50 minute after start Ghe infusion 96 min after end Of sw infusion 2 hr AFTER end of Ghe infusion Pre dose sw PRE DOSE sw sw after bedtime **** new ***** a very long string that ends with Ghe **** new ***** ;run;

Here are two suggestions for treating these cases correctly: 1. pre- and postfix the input to TRANWRD with a blank and LEFT justify: data want; set have; SDE=left(tranwrd(' '!!SDE!!' ',' sw ',' ')); SDE=left(tranwrd(' '!!SDE!!' ',' Ghe ',' ')); run;

or 2. Use PRX: data want; set have; if _n_=1 then do; prxDelete=prxparse('s/(^| )(?:sw|Ghe)(?:$| )/$1/'); end; retain prx:; drop prx:; SDE=prxChange(prxDelete,-1,SDE); run;

The PRXPARSE string: "s" modifier means "switch", i.e. a change string operation "/" prx delimiter, start of change from string "(^| )" a capturing (can be referenced with $1) buffer, containing beginning of string or a blank "(?:sw|Ghe)" noncapturing buffer (less overhead) with "sw" or "Ghe" "(?:$| )" noncapturing buffer with end of string or blank "/" prx delimiter, end of change from string, start of change to string "$1" the contents of capture buffer (nothing if start of line, else blank) "/" prx delimiter, end of change to string

Regards, Søren

On Thu, 9 Sep 2010 14:34:26 -0400, Tom Smith <need_sas_help@YAHOO.COM> wrote:

>I have a character variable named "SDE" in a dataset as below where I have >to get >rid of a part of the values which are "sw" or "Ghe". > >SDE >--- >10 after after End Of sw infusion >5 minute After end OF sw infusion >50 minute after start Ghe infusion >96 min after end Of sw infusion >2 hr AFTER end of Ghe infusion >Pre dose sw >PRE DOSE sw > > >the result should be as below: > >SDE >--- >10 after after End Of infusion >5 minute After end OF infusion >50 minute after start infusion >96 min after end Of infusion >2 hr AFTER end of infusion >Pre dose >PRE DOSE > > >Thank you so much from the bottom, of my heart.


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