Date: Fri, 9 Jan 2009 10:26:15 -0600
Reply-To: "./ ADD NAME=Data _null_," <iebupdte@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "./ ADD NAME=Data _null_," <iebupdte@GMAIL.COM>
Subject: Re: how to find streak of numbers in character string?
In-Reply-To: <d6a0d8f10901090802g789d82b0v690511511b3e06da@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
What if you use PRXCHANGE to change the target to a character that is
unlikely to be found in the string and then COUNT those characters.
1245 data _null_;
1246 text ='Like c1 or C101 or c23 or d234';
1247 matches = count(prxchange("s/[A-Za-z]\d+/~/",-1,text),'~');
1248 put (_all_)(=/);
1249 run;
text=Like c1 or C101 or c23 or d234
matches=4
On 1/9/09, karma <dorjetarap@googlemail.com> wrote:
> Forgot to add a condition to it:
>
> data test;
> text ='Like c1 or c101 or c23 or c234';
> start=1;
> stop=length(text);
> pattern=prxparse("/c\d+/");
> call prxnext(pattern, start, stop, text, position, length);
> if position then do matches=1 by 1 while (position and start<stop);
> call prxnext(pattern, start, stop, text, position, length);
> end;
> run;
>
> 2009/1/9 karma <dorjetarap@googlemail.com>:
> > Unfortunately I don't think there is a function to count patterns in
> > SAS --I really wish there was a prx way to handle this :(
> > Anyway, here is a looping method to handle it. If you want to
> > explicitly state the number of matches for the digits you are looking
> > for then replace the "+" in the pattern with "{n}" to specify the
> > number of digits you want to match.
> >
> > HTH
> >
> > data test;
> > text ='Like c1 or c101 or c23 or c234';
> > start=1;
> > stop=length(text);
> > pattern=prxparse("/c\d+/");
> > call prxnext(pattern, start, stop, text, position, length);
> > do matches=1 by 1 while (position and start<stop);
> > call prxnext(pattern, start, stop, text, position, length);
> > end;
> > run;
> >
> > 2009/1/9 Adriano Rodrigues <adriano@gpp.com.br>:
> >> Thanks all,
> >>
> >> One more doubt, how may i find how many strings like letter C followed by
> >> any numbers appear in string?
> >>
> >> Like c1 or c101 or c23 or c234,
> >>
> >> I would want count too cnumber=count(string,"Canynumberstreak") is any
> >> special character I can use? Like "C###"
> >>
> >> Adriano
> >>
> >>
> >> -----Mensagem original-----
> >> De: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] Em nome de ./ ADD
> >> NAME=Data _null_,
> >> Enviada em: sexta-feira, 9 de janeiro de 2009 05:38
> >> Para: SAS-L@LISTSERV.UGA.EDU
> >> Assunto: Re: how to find streak of numbers in character string?
> >>
> >> FindC looks like a good choice of function for this job.
> >>
> >> Data strings;
> >> Input string $ 60.;
> >> e=1;
> >> do _n_= 1 by 1 until(s eq 0);
> >> s = findc(string,'0123456789',e);
> >> e = findc(string,'0123456789',s,'V');
> >> end;
> >> numberstreaks = _n_ - 1;
> >> drop s e;
> >> Cards;
> >> AC BB 203 CC 404
> >> ACX 88 CC
> >> AC BB 20 3CC404
> >> AC BB 915 CC 404
> >> AC BB 03 CC 404
> >> AC BB 503 CC 404 X 55463
> >> BF DDFAR
> >> ;;;;
> >> run;
> >> proc print;
> >> run;
> >>
> >> On 1/9/09, Adriano Rodrigues <adriano@gpp.com.br> wrote:
> >>> Hi all,
> >>>
> >>>
> >>>
> >>> Having character strings, I want know how many streaks of numbers each
> >>> string has, witch functions may I use for it?
> >>>
> >>>
> >>>
> >>> Data strings;
> >>>
> >>> Input string $ 60.;
> >>>
> >>> Cards;
> >>>
> >>> AC BB 203 CC 404
> >>>
> >>> ACX 88 CC
> >>>
> >>> AC BB 20 3CC404
> >>>
> >>> AC BB 915 CC 404
> >>>
> >>> AC BB 03 CC 404
> >>>
> >>> AC BB 503 CC 404 X 55463
> >>>
> >>> BF DDFAR
> >>>
> >>> ;
> >>>
> >>> run;
> >>>
> >>>
> >>>
> >>> desired output:
> >>>
> >>> string numberstreaks
> >>>
> >>> AC BB 203 CC 404 2
> >>>
> >>> ACX 88 CC 1
> >>>
> >>> AC BB 20 3CC404 3
> >>>
> >>> AC BB 915 CC 404 2
> >>>
> >>> AC BB 03 CC 404 2
> >>>
> >>> AC BB 503 CC 404 X 55463 3
> >>>
> >>> BF DDFAR 0
> >>>
> >>>
> >>>
> >>> Thanks!
> >>>
> >>> Adriano
> >>>
> >>
> >
>
|