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;
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.
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.