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

Hi there,

 

Sorry I am just starting out using SAS. I have been doing some basic data manipulation and cannot seem to find a how-to on using the wildcard function with IF statements.

 

Here is what I wrote;

data work.cars;
set work.cars;
if displ=>0 and City_MPG=>30 and model^="*hydrid*" then Eff='Yes';
if Model='%Hybrid%' then Eff='Hyb';
run;

 

I am simply trying to weed out any vehicle models that have Hybrid (non-case sensitive if possible) in their name from my Eff(icient) column. What have I done incorrectly? It isn't giving me errors, but the Hybrid vehicles are not changing to "Hyb", they are just saying "Yes" from my previous IF statement.


Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
mohamed_zaki
Barite | Level 11

use index function for that

if index(LOWCASE(model),'hybrid') then ....

View solution in original post

3 REPLIES 3
mohamed_zaki
Barite | Level 11

use index function for that

if index(LOWCASE(model),'hybrid') then ....
FreelanceReinh
Jade | Level 19

Hi @wy2sl0,

 

In string comparisons in the DATA step those "wildcard" characters have no special meaning. They are treated as ordinary characters.

 

The LIKE condition in PROC SQL, however, uses the percent sign and the underscore (not the asterisk) as wildcard characters. But I haven't seen or used this very often, because there are other tools available, e.g. character functions such as the INDEX function suggested by mohamed_zaki.

 

In any case you should avoid typos such as "hydrid" when coding string comparisons. (Or did you really mean "hydrid"?)

wy2sl0
Calcite | Level 5

Total mistake! I am going to try the advice given after dinner thanks you two.


EDIT: It worked perfectly! Thanks so much! This is a very important IF statement I will need to use. Appreciate it!

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Develop Code with SAS Studio

Get started using SAS Studio to write, run and debug your SAS programs.

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
  • 3 replies
  • 10061 views
  • 2 likes
  • 3 in conversation