DATA Step, Macro, Functions and more

Not Contains

Reply
Occasional Contributor
Posts: 15

Not Contains

if (trim(put(Name,test30.)) not contains ('RICHARD NU')) ;

test30. is a format from format dataset.

When I am trying as above I am getting error as
Syntax error, expecting one of the following: <, <=, =, >, >=, EQ, GE, GT, LE,
LT, NE, NG, NL, ^=, ~=.
but I dont want to use NE . I should use 'not contains' . Is it possible with 'not contains'? Thanks .
Frequent Contributor
Posts: 127

Re: Not Contains

Hi,

The (not) Contains condtion is to be used within a Proc SQL statement and cannot be used within a datastep.

Hope it helps.

Kind regards,
Florent

Example:
--------------
Proc sql;
create table as
select *
from
where (trim(put(Name,test30.)) not contains ('RICHARD NU')) ;
quit;
N/A
Posts: 0

Re: Not Contains

Excuse me, what it's the difference between NE and not contains ?
Super Contributor
Super Contributor
Posts: 3,174

Re: Not Contains

The "NE" operator is either an exact-match or by adding ":" tests a prefix value. The "NOT CONTAINS" tests/scans the specified SAS variable for the argument string, as coded in your example.

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic/post:

+"not contains" site:sas.com
N/A
Posts: 0

Re: Not Contains

Assuming this is data step code, either one of the find() or index() functions should produce the desired result:

if index((trim(put(Name,test30.)) , 'RICHARD NU');

See the documentation for more details.

Jonathan

> if (trim(put(Name,test30.)) not contains ('RICHARD
> NU')) ;
>
> est30. is a format from format dataset.
>
> When I am trying as above I am getting error as
> Syntax error, expecting one of the following: <, <=,
> =, >, >=, EQ, GE, GT, LE,
> LT, NE, NG, NL, ^=, ~=.
> t to use NE . I should use 'not contains' . Is it
> possible with 'not contains'? Thanks .
Occasional Contributor
Posts: 5

Re: Not Contains

I use NOT CONTAINS within SAS Miner. I often have to consider the data structure. If the data set is unstructured, like a paragraph of text, NOT CONTAINS often provides you a little more freedom compared to NE to parse the text.

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