| Date: | Tue, 23 Jan 2007 23:25:21 -0800 |
| Reply-To: | David L Cassell <davidlcassell@MSN.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | David L Cassell <davidlcassell@MSN.COM> |
| Subject: | Re: substr, scan |
| In-Reply-To: | <BAY123-F324B23D7739C3463744CDDEAC0@phx.gbl> |
| Content-Type: | text/plain; format=flowed |
|---|
tobydunn@HOTMAIL.COM wrote back:
>
>On Wed, 24 Jan 2007 04:07:13 +0000, toby dunn <tobydunn@HOTMAIL.COM> wrote:
>
> >Art ,
> >
> >Ian leaves me confused quite a bit and I often find careful, thoughful,
>and
> >often long study of what he says yeilds some perl of wisdom. I would
>rather
> >think Ian is saying that this particular text parsing problem has been
> >solved using PRX. So why use something that is less robust to solve the
> >problem, well the level of skil in a shop is one valid reason I can see.
> >But pushing th limits every now and again ussually isnt a bad thing.
>Heck
> >if we never ventured out we would get no where in our development.
> >
> >So to that end I offer this PRX solution that may very well make Perl
>heads
> >cringe...
> >
> >data test;
> >input var $11. ;
> >datalines;
> >w2y
> >w34y4h
> >w38h45m23s
> >p5d23m
> >p61h
> >w56s
> >;
> >run;
> >
> >
> >Data Need ( Keep = Var Sec Min Hour ) ;
> >Set Test ;
> >Retain Pattern ;
> >
> >If _N_ = 1 Then Pattern = PRXParse( "/\d+[smh]/" ) ;
> >
> >Start = 1 ;
> >Stop = Length( Var ) ;
> >
> >Call PrxNext( Pattern , Start , Stop , Var , Match , Length ) ;
> >
> >Do I = 1 By 1 While( ( Match > 0 ) and ( I < Stop ) ) ;
> >
> > Temp = Substr( Var , Match , Length ) ;
> >
> > If Index( Temp , 's' ) Then Sec = Input( Compress( Temp , 's' ) ,
>8.
> >) ;
> > Else If Index( Temp , 'm' ) Then Min = Input( Compress( Temp , 'm' ) ,
>8.
> >) ;
> > Else If Index( Temp , 'h' ) Then Hour = Input( Compress( Temp , 'h' ) ,
>8.
> >) ;
> >
> > Call PrxNext( Pattern , Start , Stop , Var , Match , Length ) ;
> >End ;
> >
> >
> >Run ;
> >
> >
> >Proc Print
> >data = Need ;
> >Run ;
> >
> >
> >
> >Toby Dunn
> >
>
>Both the INDEX and COMPRESS functions above could be replaced with regex.
>
>Ken
>
>Ken ,
>
>Geez man do I look like a Perl head....
I'll take the Fifth, your honor. :-)
> I just muddle my way through when it
>comes to Perl. I just wished it was easier to read.
>
Check out the /x modifier, so you can insert spacing for readability.
It's not as good as what the /x modifier does in Perl, but it's better
than a poke in the eye with a sharp stick.
HTCT,
David
--
David L. Cassell
mathematical statistician
Design Pathways
3115 NW Norwood Pl.
Corvallis OR 97330
_________________________________________________________________
Valentine’s Day -- Shop for gifts that spell L-O-V-E at MSN Shopping
http://shopping.msn.com/content/shp/?ctId=8323,ptnrid=37,ptnrdata=24095&tcode=wlmtagline
|