BookmarkSubscribeRSS Feed
RoWa
Calcite | Level 5

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;

5 REPLIES 5
nehalsanghvi
Pyrite | Level 9
SQL version would be:

Proc sql;
Create table want as
Select *
From have
Where acct_name not like '%CARD%';
Quit;
nehalsanghvi
Pyrite | Level 9
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;
Reeza
Super User

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.

 

 

art297
Opal | Level 21

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

 

ChrisNZ
Tourmaline | Level 20

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 2549 views
  • 0 likes
  • 5 in conversation