Date: Mon, 16 Jun 1997 13:45:00 -0500
Reply-To: kalfast <kalfast@PPRD.ABBOTT.COM>
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: kalfast <kalfast@PPRD.ABBOTT.COM>
Organization: Abbott Laboratories
Subject: Re: string compression
Content-Type: text/plain; charset=us-ascii
kalfast wrote:
>
> William Robb wrote:
> >
> > Mighty guru-type-people:
> > One of our in-house wizards answered my question about
> > removing all non-numeric characters from a string. Here is a
> > bit of sample code for you to improve upon....
> >
> > 1 data _null_;
> > 2 strdata = '58durb864DMF951206VEb34*@4W';
> > 3 do i = 1 to length(strdata);
> > 4 if not index('1234567890',substr(strdata,i,1))
> > 5 then substr(strdata,i,1) = ' ';
> > 6 end;
> > 7 strdata=compress(strdata);
> > 8 put strdata;
> > 9 run;
> >
> > 58864951206344
> > NOTE: The DATA Statement used 0.71 seconds.
> >
> > NOTE: SAS Institute Inc., SAS Campus Drive, Cary, NC USA
>
> You can speed things up by eliminating the DO loop in favor of a
> revised call to the COMPRESS function (although the "not index"
> method is safer if new characters are added). For example:
>
> data _null_;
> alphastr='~`!@#$%^&*()-_=+[{]}\|;",<.>/?'||"'"||
> 'qwertyuiopasdfghjklzxcvbnm'||
> 'QWERTYUIOPASDFGHJKLZXCVBNM';
> put strdata=;
> strdata=compress(strdata,alphastr);
> run;
>
> /***** OR *****/
>
> data _null_;
> strdata='58durb864DMF951206VEb34*@4W';
> strdata=compress(strdata,
> '~`!@#$%^&*()-_=+[{]}\|;",<.>/?'||"'"||
> 'qwertyuiopasdfghjklzxcvbnm'||
> 'QWERTYUIOPASDFGHJKLZXCVBNM');
> put strdata=;
> run;
Duh. Rather than risking carpal tunnel, use:
strdata=compress(strdata,compress(strdata,'0123456789'));
Hey, it's Monday...give me a break!
Tom
--
Thomas Kalfas, Consultant
Abbott Laboratories
E-mail: kalfast@pprd.abbott.com
Phone: (847) 938-8101
Fax: (847) 938-1736
|