Bonjour les experts,
Savez-vous, s’il vous plaît, comment marquer les espaces à l’intérieur de la fonction prxmatch :
Je souhaite avoir les données avec T6 et T 6 :
if (prxmatch("/T6/",lb_c)>0 and (prxmatch("/T 6/",lb_c)>0
Merci !
Utilisez le mot-clé \s pour supprimer les espaces.
if prxmatch("/T\s*6/",lb_c)>0
Here * means zero space or at least one space.
Bonjour @SASdevAnneMarie,
data test; input lb_c $20.; crit1=prxmatch("/T6/",lb_c) and prxmatch("/T 6/",lb_c); crit2=prxmatch("/T6/",lb_c) or prxmatch("/T 6/",lb_c); label crit1='Contains both "T6" and "T 6"' crit2='Contains "T6" or "T 6" (or both)'; cards; ...... ...T6... ...T 6... ...T 6...T6... ...T6...T 6... ; proc print data=test label; run;
Result:
Contains Contains "T6" or both "T6" "T 6" Obs lb_c and "T 6" (or both) 1 ...... 0 0 2 ...T6... 0 1 3 ...T 6... 0 1 4 ...T 6...T6... 1 1 5 ...T6...T 6... 1 1
More people could help you if you ask your question in English, provide some test data in usable form and results of your experiments up to now...
Try this:
data have;
input lb_c $ 64.;
cards;
T6 /* yes */
T 6 /* yes */
ABC T6 DEF /* yes */
abc T 6 def /* yes */
abc TX6 efg /* no */
abcT6efg /* ??? */
abcT 6efg /* ??? */
;
run;
proc print;
run;
data want;
set have;
flag = prxmatch("/T6|T\ 6/",lb_c)>0;
run;
proc print;
run;
EDIT:
Alternative form:
flag = prxmatch("/(T( )?6)/",lb_c)>0;
Bart
No worries, we figured the problem out and that's the most important! 🙂 🙂
Utilisez le mot-clé \s pour supprimer les espaces.
if prxmatch("/T\s*6/",lb_c)>0
Here * means zero space or at least one space.
The "\s*" will give us "T6" (zero spaces), and "T 6"(one space), but also "T 6" (thousands spaces). Wasn't to OP about 0 or 1 space? Or did I misunderstand it?
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.