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.
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;
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;
Can't we use wildcards in if clause?
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;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.