BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SASACC
Calcite | Level 5
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 .
1 ACCEPTED SOLUTION

Accepted Solutions
deleted_user
Not applicable

Editor's Note: The CONTAINS operator is valid in a WHERE clause, not an IF statement. As shown by @deleted_user, using the INDEX or the FIND functions provide the closest equivalent. There is also a SAS Note, Sample 43303, that discusses this.

 

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 .

View solution in original post

5 REPLIES 5
Florent
Quartz | Level 8
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;
deleted_user
Not applicable
Excuse me, what it's the difference between NE and not contains ?
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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
deleted_user
Not applicable

Editor's Note: The CONTAINS operator is valid in a WHERE clause, not an IF statement. As shown by @deleted_user, using the INDEX or the FIND functions provide the closest equivalent. There is also a SAS Note, Sample 43303, that discusses this.

 

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 .

C_Ishihara
Calcite | Level 5

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.

sas-innovate-2024.png

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.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 48576 views
  • 1 like
  • 5 in conversation