DATA Step, Macro, Functions and more

Sound-LIke in data step / contains in Sql

Reply
New Contributor
Posts: 4

Sound-LIke in data step / contains in Sql

Hello,

 

I am trying to delete the observation that does NOT contain "Card", and I am doing it in the data step. it gave me error on the =* and delete. I am not too sure what was wrong with it, can you please help?

 

can I do this in the sql step??

 

Thank you. 

 

data want;

set have;

if acct_name not =* 'CARD' then delete;

run;

Frequent Contributor
Posts: 75

Re: Sound-LIke in data step / contains in Sql

SQL version would be:

Proc sql;
Create table want as
Select *
From have
Where acct_name not like '%CARD%';
Quit;
Frequent Contributor
Posts: 75

Re: Sound-LIke in data step / contains in Sql

Oops, please exclude the 'not' from the query I posted. I did the opposite above. This is what you need:

Proc sql;
Create table want as
Select *
From have
Where acct_name like '%CARD%';
Quit;
Super User
Posts: 19,851

Re: Sound-LIke in data step / contains in Sql

Sounds like is a SQL operator, not a data step operator. 

 

But you could use it in a WHERE statement, use a SQL query instead or use the FIND or INDEX functions in place of it. One thing the INDEX and FIND can do is ignore case, if specified to do so.

 

 

PROC Star
Posts: 7,487

Re: Sound-LIke in data step / contains in Sql

You can use the contains operator in a datastep where clause. e.g.:

 

data want;
  set have (where=(acct_name contains 'CARD'));
run;

HTH,

Art, CEO, AnalystFinder.com

 

PROC Star
Posts: 1,760

Re: Sound-LIke in data step / contains in Sql

[ Edited ]

While IF and WHERE are largely interchangeable from a syntax view point, some operators or functions can only be used in one of them.

 

WHERE can use operators such as like, contains, sounds like, or between as they come from the SQL world where WHERE clauses are used.

 

IF can use functions such as lag or vvalue or attrn as these belong firmly to the SAS world only.

Ask a Question
Discussion stats
  • 5 replies
  • 257 views
  • 0 likes
  • 5 in conversation