Date: Thu, 8 Jul 2010 13:27:02 +0000
Reply-To: "Keintz, H. Mark" <mkeintz@WHARTON.UPENN.EDU>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Keintz, H. Mark" <mkeintz@WHARTON.UPENN.EDU>
Subject: Re: How to compress muliple decimal points
Content-Type: text/plain; charset="us-ascii"
How about this approach, based on the following logic?
1. Find position of the first decimal point.
2. Compress out all subsequent decimal points
(i.e. both trailing and internal)
This requires no distinct treatment of trailing decimal points
versus excess internal decimal points. The "trick" here is to
to utilize the ability of the SUBSTR function (unique among
functions, no?) to be used on the left side of an assignment
input text $;
put "Before " text= @;
if ix>0 then substr(text,ix+1)=compress(substr(text,ix+1),'.');
put @22 "After " text= ;
> -----Original Message-----
> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
> Arthur Tabachneck
> Sent: Wednesday, July 07, 2010 9:42 AM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Re: How to compress muliple decimal points
> Tom's suggestion is definitely a lot less brute looking than the
> following, but doesn't correct for one of your examples. There is
> probably a much easier way, but the following will at least accomplish
> data have;
> input (x y) ($);
> do i=1 to length(x);
> if substr(x,i,1) eq '.' then do;
> if not(got_dot) then do;
> else do;
> 37..2 s/b
> 37.2 but
> 56.2. s/b
> 56.2 s/b
> On Wed, 7 Jul 2010 08:57:40 -0400, Dave Brewer <david.brewer@UC.EDU>
> >Thanks for your solution. I was thinking of TRANWRD, but for some dumb
> >reason, I didn't think I could put in two decimal points.
> >Thanks again.
> >On Wed, 7 Jul 2010 08:36:29 -0400, Tom Abernathy
> >>Dave -
> >> A simple thing is to use TRANWRD function.
> >> clean = tranwrd( old , '..' , '.' );
> >> Another trick I have used to eliminate dups is to switch the
> >>with the space character and use the COMPBL function, then switch
> >>This will handle 2, 3 or more characters in a row in one pass.
> >> new = translate( old , ' .' , '. ' );
> >> new = compbl( new );
> >> new = translate( new , ' .' , '. ' );
> >>- Tom
> >>On Wed, 7 Jul 2010 07:07:23 -0400, Dave Brewer <david.brewer@UC.EDU>
> >>>Hi All,
> >>>I'm sure there is a simple answer to my problem, but I can't see the
> >>>forest through the trees!
> >>>How do I replace multiple decimal points with one when the decimals
> >>>back-to-back? Ex) 37..2 s/b 37.2 but 56.2. s/b 56.2
> >>>I am trying to clean up dirty data and keep as many values as
> >>>without making them missing.