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!
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;
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;
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;
See Maxim 4.
Try It.
Create fake data:
data have;
input cd_produit $;
datalines;
PE01GB
PE33GB
PE67GB
XXXXXX
;
and run your SQL on it.
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!
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.