Bonjour,
je réalise des REGEX pour normaliser des chaines de caractères complexes présentes dans mes données.
J'ai écrit un bout de code avec des assertions arrières qui pose pas de problèmes
voici un exemple
qui me fait quelques transformations (cf ci dessous)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 data a; length var $40; var='totoAB CD';output; var='totoA CD';output; var='*V* *D3 *I*TiTiToTo*I*';output; var='*I* *D3 *I*Pif&Paf*I*';output; var='*IN* *D3 *I*Pif&Paf*I*';output; var='*V* *D3 TaTa';output; var='*N* *D3 *I*TiTiToTo*I*';output; run; data b; set a; retain regex; if _n_=1 then do; regex=prxparse('s/(?<=[VIL]\*\s\*(?:D[1-9A]|L[1-4]))\s\*[VIL]\*([^\*]+)\*[VIL]\*\s/# $1 /'); end; if prxmatch(regex,var) then var2=prxchange(regex,1,var); run; proc print data=b;run;
Les transformations sont déterminées par les balises *caractère*
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10 Obs var regex var2 1 totoAB CD 1 2 totoA CD 1 3 *V* *D3 *I*TiTiToTo*I* 1 *V* *D3# TiTiToTo 4 *I* *D3 *I*Pif&Paf*I* 1 *I* *D3# Pif&Paf 5 *IN* *D3 *I*Pif&Paf*I* 1 6 *V* *D3 TaTa 1 7 *N* *D3 *I*TiTiToTo*I* 1
Je voulais faire des variantes à deux caractères de mes balises*
Par exemple je voulais que la regex reconnaisse non seulement
*V* , *I* et *L* mais également *VN* , *IN* et *LN*
Donc je me suis dit, c'est simple il suffit de remplacer la description de tes balises qui s'écrivent en [VIL]\* ou \*[VIL]\*
par [VIL]N?\* ou \*[VIL]N?\*
et là à ma grande surprise SAS n'accepte pas à la compilation
ce qui donne en log
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 data b; set a; retain regex; if _n_=1 then do; regex=prxparse('s/(?<=[VIL]N?\*\s\*(?:D[1-9A]|L[1-4]))\s\*[VIL]N?\*([^\*]+)\*[VIL]N?\*\s/# $1 /'); end; if prxmatch(regex,var) then var2=prxchange(regex,1,var); run;
Je me dit ok c'est le ? qui pose problème donc j'ai remplacé le
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52 ERROR: Variable length lookbehind not implemented before HERE mark in regex m/(?<=[VIL]N?\*\s\*(?:D[1-9A]|L[1-4]))\s\*[VIL]N?\*([^\*]+)\*[VIL]N?\*\s << HERE /. ERROR: The regular expression passed to the function PRXPARSE contains a syntax error. NOTE: Argument 1 to function PRXPARSE at line 9601 column 7 is invalid. NOTE: Argument 1 to the function PRXMATCH is missing. ERROR: Argument 1 to the function PRXMATCH must be a positive integer returned by PRXPARSE for a valid pattern. NOTE: Argument 1 to function PRXMATCH at line 9603 column 4 is invalid. var=totoAB CD regex=. var2= _ERROR_=1 _N_=1 NOTE: Argument 1 to the function PRXMATCH is missing. ERROR: Argument 1 to the function PRXMATCH must be a positive integer returned by PRXPARSE for a valid pattern. NOTE: Argument 1 to function PRXMATCH at line 9603 column 4 is invalid. var=totoA CD regex=. var2= _ERROR_=1 _N_=2 NOTE: Argument 1 to the function PRXMATCH is missing. ERROR: Argument 1 to the function PRXMATCH must be a positive integer returned by PRXPARSE for a valid pattern. NOTE: Argument 1 to function PRXMATCH at line 9603 column 4 is invalid. var=*V* *D3 *I*TiTiToTo*I* regex=. var2= _ERROR_=1 _N_=3 NOTE: Argument 1 to the function PRXMATCH is missing. ERROR: Argument 1 to the function PRXMATCH must be a positive integer returned by PRXPARSE for a valid pattern. NOTE: Argument 1 to function PRXMATCH at line 9603 column 4 is invalid. var=*I* *D3 *I*Pif&Paf*I* regex=. var2= _ERROR_=1 _N_=4 NOTE: Argument 1 to the function PRXMATCH is missing. ERROR: Argument 1 to the function PRXMATCH must be a positive integer returned by PRXPARSE for a valid pattern. NOTE: Argument 1 to function PRXMATCH at line 9603 column 4 is invalid. var=*IN* *D3 *I*Pif&Paf*I* regex=. var2= _ERROR_=1 _N_=5 NOTE: Argument 1 to the function PRXMATCH is missing. ERROR: Argument 1 to the function PRXMATCH must be a positive integer returned by PRXPARSE for a valid pattern. NOTE: Argument 1 to function PRXMATCH at line 9603 column 4 is invalid. var=*V* *D3 TaTa regex=. var2= _ERROR_=1 _N_=6 NOTE: Argument 1 to the function PRXMATCH is missing. ERROR: Argument 1 to the function PRXMATCH must be a positive integer returned by PRXPARSE for a valid pattern. NOTE: Argument 1 to function PRXMATCH at line 9603 column 4 is invalid. var=*N* *D3 *I*TiTiToTo*I* regex=. var2= _ERROR_=1 _N_=7 NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to missing values. Each place is given by: (Number of times) at (Line):(Column). 1 at 9601:7 7 at 9603:4 NOTE: There were 7 observations read from the data set WORK.A. NOTE: The data set WORK.B has 7 observations and 3 variables. NOTE: Compressing data set WORK.B increased size by 100.00 percent. Compressed is 2 pages; un-compressed would require 1 pages. NOTE: DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds
([VIL]N?) par (?:[VIL]N|[VIL])
etv là paf ! même problème
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9 data b; set a; retain regex; if _n_=1 then do; regex=prxparse('s/(?<=(?:[VIL]N|[VIL])\*\s\*(?:D[1-9A]|L[1-4]))\s\*(?:[VIL]N|[VIL])\*([^\*]+)\*(?:[VIL]N|[VIL])\*\s/# $1 /'); end; if prxmatch(regex,var) then var2=prxchange(regex,1,var); run; proc print data=b;run;
or à regarder mon code, j'ai déjà dans l'assertion arrière une expression similaire qui ne pose pas de problèmes à la compilation
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53 ERROR: Variable length lookbehind not implemented before HERE mark in regex m/(?<=(?:[VIL]N|[VIL])\*\s\*(?:D[1-9A]|L[1-4]))\s\*(?:[VIL]N|[VIL])\*([^\*]+)\*(?:[VIL]N|[VIL]) \*\s << HERE /. ERROR: The regular expression passed to the function PRXPARSE contains a syntax error. NOTE: Argument 1 to function PRXPARSE at line 9609 column 7 is invalid. NOTE: Argument 1 to the function PRXMATCH is missing. ERROR: Argument 1 to the function PRXMATCH must be a positive integer returned by PRXPARSE for a valid pattern. NOTE: Argument 1 to function PRXMATCH at line 9611 column 4 is invalid. var=totoAB CD regex=. var2= _ERROR_=1 _N_=1 NOTE: Argument 1 to the function PRXMATCH is missing. ERROR: Argument 1 to the function PRXMATCH must be a positive integer returned by PRXPARSE for a valid pattern. NOTE: Argument 1 to function PRXMATCH at line 9611 column 4 is invalid. var=totoA CD regex=. var2= _ERROR_=1 _N_=2 NOTE: Argument 1 to the function PRXMATCH is missing. ERROR: Argument 1 to the function PRXMATCH must be a positive integer returned by PRXPARSE for a valid pattern. NOTE: Argument 1 to function PRXMATCH at line 9611 column 4 is invalid. var=*V* *D3 *I*TiTiToTo*I* regex=. var2= _ERROR_=1 _N_=3 NOTE: Argument 1 to the function PRXMATCH is missing. ERROR: Argument 1 to the function PRXMATCH must be a positive integer returned by PRXPARSE for a valid pattern. NOTE: Argument 1 to function PRXMATCH at line 9611 column 4 is invalid. var=*I* *D3 *I*Pif&Paf*I* regex=. var2= _ERROR_=1 _N_=4 NOTE: Argument 1 to the function PRXMATCH is missing. ERROR: Argument 1 to the function PRXMATCH must be a positive integer returned by PRXPARSE for a valid pattern. NOTE: Argument 1 to function PRXMATCH at line 9611 column 4 is invalid. var=*IN* *D3 *I*Pif&Paf*I* regex=. var2= _ERROR_=1 _N_=5 NOTE: Argument 1 to the function PRXMATCH is missing. ERROR: Argument 1 to the function PRXMATCH must be a positive integer returned by PRXPARSE for a valid pattern. NOTE: Argument 1 to function PRXMATCH at line 9611 column 4 is invalid. var=*V* *D3 TaTa regex=. var2= _ERROR_=1 _N_=6 NOTE: Argument 1 to the function PRXMATCH is missing. ERROR: Argument 1 to the function PRXMATCH must be a positive integer returned by PRXPARSE for a valid pattern. NOTE: Argument 1 to function PRXMATCH at line 9611 column 4 is invalid. var=*N* *D3 *I*TiTiToTo*I* regex=. var2= _ERROR_=1 _N_=7 NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to missing values. Each place is given by: (Number of times) at (Line):(Column). 1 at 9609:7 7 at 9611:4 NOTE: There were 7 observations read from the data set WORK.A. NOTE: The data set WORK.B has 7 observations and 3 variables. NOTE: Compressing data set WORK.B increased size by 100.00 percent. Compressed is 2 pages; un-compressed would require 1 pages. NOTE: DATA statement used (Total process time): real time 0.00 seconds cpu time 0.00 secondsJe n'y comprend pas grand chose, où se situe le problème ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part (?:D[1-9A]|L[1-4])
Partager