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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 425 views
  • 0 likes
  • 3 in conversation