At the regex101.com page my regular expression does what I want it to do.
But I cannot use the ungreedy option in the prxparse option.
I want to output any text within data|proc and run|quit. So where I get stuck is the casuser.want part at the end of the code.
Calling the expert, @Ksharp any idea?
The first example code is taken form https://communities.sas.com/t5/SAS-Programming/Scan-a-string-to-find-word-after-a-specific-word/m-p/684526
data casuser.codi1;
infile datalines4 dsd ;
length text $2000 ;
input text$ ;
datalines4;
data want;
string = "my aim is to find every word after bank_beg.upa for every bank_beg.xx in this line bank_beg.ff";
length want $ 80;
pid=prxparse('/(?<=bank_beg\.)\w+/i');
s=1;e=length(string);
call prxnext(pid,s,e,string,p,l);
do while(p>0);
want=catx(' ',want,substr(string,p,l));
call prxnext(pid,s,e,string,p,l);
end;
drop s e p l pid;
run;
data ReversedNames;
input name & $100.;
datalines;
Activa contractual
Anulada antes de firmada
Cancelacion Long Drive. CPC-NEXT
Cancelacion Long Drive. Decision Cliente
Cancelacion Long Drive. Desconocimiento producto
Cancelacion Long Drive. Descontento exceso KMS
Cancelacion Long Drive. Impagados
Cancelacion Long Drive. Importe cuota elevada
Cancelacion Long Drive. No se ajusta a sus necesidades
Cancelacion Long Drive. Perdida total (robo/siniestro)
Cancelacion Long Drive. Uso intensivo vehiculo MAX.Permitido
Cancelacion Long Drive. Uso publico excesivo (TAXI)
Cancelacion Long Drive. Venta del vehiculo
Finiquitada LONG DRIVE por excedido tranquilidad SEAT
Finiquitada LONG DRIVE por kilometraje
Finiquitada LONG DRIVE por tiempo
;
run;
data FirstLastNames;
length first last $ 16;
keep first last name situation;
retain re;
if _N_ = 1 then
re = prxparse('/(canc|anul*)?(fini*)?(activ*)*/i');
set ReversedNames;
if prxmatch(re, name) then
do;
last = prxposn(re, 1, name);
first = prxposn(re, 2, name);
situation=choosec(max(
^missing(prxposn(re, 1, name))*1, ^missing(prxposn(re, 2, name))*2, ^missing(prxposn(re, 3, name))*3),
'cancelada/anulada', 'finiquitada', 'activa' );
end;
run;
proc sql;
select * from oks;
quit;
;;;;
run;
data _null_;
do i = 1 to 1;
call execute ("data casuser.codi_desc" || strip(put(i,$2.)) ||
"; set casuser.codi" || strip(put(i,$2.)) || " end=eof;
length textus varchar(10000);
did=" || i || " ;
retain textus;
textus=cats(textus, text);
if eof then do;
textus =tranwrd(textus,';',cat(';', '0A'x));
output;
end;
run;");
end;
run;
data casuser.want;
set CASUSER.CODI_DESC1;
length want $ 32000;
pid=prxparse('/^\s?(data|proc)(.*\n)*(?=(quit|run))(run|quit);/i');
s=1;e=length(textus);
call prxnext(pid,s,e,textus,p,l);
do while(p>0);
want=substr(textus,p,l);
output;
call prxnext(pid,s,e,textus,p,l);
end;
/* drop s e p l pid; */
run;
... View more