DATA Step, Macro, Functions and more

Wildcards in datastep

Accepted Solution Solved
Reply
Super Contributor
Posts: 426
Accepted Solution

Wildcards in datastep

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.


Accepted Solutions
Solution
‎02-24-2015 05:30 AM
Respected Advisor
Posts: 3,894

Re: Wildcards in datastep

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


All Replies
Solution
‎02-24-2015 05:30 AM
Respected Advisor
Posts: 3,894

Re: Wildcards in datastep

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;

Super Contributor
Posts: 426

Re: Wildcards in datastep

Can't we use wildcards in if clause?

Super User
Super User
Posts: 6,502

Re: Wildcards in datastep

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;

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 656 views
  • 3 likes
  • 3 in conversation