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

I've a code like below.

data a;

  input zip $ name $;

  datalines;

12345 ram

67891 ravi

01/45 raju

10/46 kumar

;

run;

Followed by I need to delete the records if the variable zip has slash (/) between them. I know it can be done via find or index function. But I wish to understand if it can be done by wildcards. e.g. if zip like '%/%' then delete.

I'm thankful for any help you offer me.

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Not sure what's the problem with find() or index() - but below a few other options I can currently think of.

data a;

  input zip $ name $;

  datalines;

12345 ram

67891 ravi

01/45 raju

10/46 kumar

;

run;

proc sql;

  create table want1 as

    select *

    from a

    where zip not like '%/%'

  ;

quit;

data want2;

  set a(where=(zip not like '%/%'));

run;

data want3;

  set a;

  where zip not like '%/%';

run;

proc sql;

  delete from a (where=(zip like '%/%'));

quit;

View solution in original post

3 REPLIES 3
Patrick
Opal | Level 21

Not sure what's the problem with find() or index() - but below a few other options I can currently think of.

data a;

  input zip $ name $;

  datalines;

12345 ram

67891 ravi

01/45 raju

10/46 kumar

;

run;

proc sql;

  create table want1 as

    select *

    from a

    where zip not like '%/%'

  ;

quit;

data want2;

  set a(where=(zip not like '%/%'));

run;

data want3;

  set a;

  where zip not like '%/%';

run;

proc sql;

  delete from a (where=(zip like '%/%'));

quit;

Babloo
Rhodochrosite | Level 12

Can't we use wildcards in if clause?

Tom
Super User Tom
Super User

IF statements do not support LIKE operator.

There are many other operators or functions you can use in the IF statement,so it is not really much of a loss.

For example:

if index(zip,'/') then delete;

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

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