SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.

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 !

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

 

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.

View solution in original post

8 REPLIES 8
FreelanceReinh
Jade | Level 19

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
yabwon
Onyx | Level 15

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

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



SASdevAnneMarie
Barite | Level 11
My apologies, I wrote in English, the site translate directly in French, I don't know why.
yabwon
Onyx | Level 15

No worries, we figured the problem out and that's the most important! 🙂 🙂

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Ksharp
Super User

 

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.

SASdevAnneMarie
Barite | Level 11
Thank you very much, Ksharp!
yabwon
Onyx | Level 15

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? 

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Ksharp
Super User
If it was about 0 or 1 space. Could try this(use ? replace with *):

if prxmatch("/T\s?6/",lb_c)>0

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 947 views
  • 3 likes
  • 4 in conversation