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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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