BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SASdevAnneMarie
Barite | Level 11

Hello,

 

I have a question please. Is it right to write the code:

where cd_produit like '%PE%GB%';

 

if I want to find the products like  PE01GB, PE33GB, PE67GB

 

Thank you very much!

 

1 ACCEPTED SOLUTION

Accepted Solutions
gamotte
Rhodochrosite | Level 12

Hello,

 

Why don't you test it and check if it suits your needs ?

 

data have;
input cd_produit $20.;
cards;
PE01GB
PE67GB
PA45GB
PE35GC
AAPE75GBCC
PEZZGB
;
run;

data want;
set have;
where cd_produit like '%PE%GB%';
run;

View solution in original post

4 REPLIES 4
gamotte
Rhodochrosite | Level 12

Hello,

 

Why don't you test it and check if it suits your needs ?

 

data have;
input cd_produit $20.;
cards;
PE01GB
PE67GB
PA45GB
PE35GC
AAPE75GBCC
PEZZGB
;
run;

data want;
set have;
where cd_produit like '%PE%GB%';
run;
SASdevAnneMarie
Barite | Level 11
Thank you, it worked also for me.I thougth that maybe there was another option to do that )
gamotte
Rhodochrosite | Level 12

Glad it helped.

 

There are always many options and you have to consider if the retained solution always

do what you expect. For instance, if your data contains products as "AAPEZZGBTT" they will match

the condition 'like "%PE%GB%". If you want to check precisely that the string is "PE" followed by

two digits followed by "GB", you can use a regexp as follows :

 

data want;
set have;
where prxmatch("/^PE\d{2}GB$/", trim(cd_produit));
run;
Kurt_Bremser
Super User

See Maxim 4.

Try It.

Create fake data:

data have;
input cd_produit $;
datalines;
PE01GB
PE33GB
PE67GB
XXXXXX
;

and run your SQL on it.

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 4 replies
  • 685 views
  • 0 likes
  • 3 in conversation