BookmarkSubscribeRSS Feed
inquistive
Quartz | Level 8

Hi SAS experts,

 

We use:

 '01AUG2022'D <= birthdate <= '05AUG2022'D (to derive birthdates that fall BETWEEN Aug 1st and Aug 5, 2022)

 

What operators do we use to say NOT BETWEEN ?

 

Thanks,

10 REPLIES 10
Reeza
Super User
NOT ('01AUG2022'D <= birthdate <= '05AUG2022'D)

birthdate < '01AUG2022'D & birthdate >'05AUG2022'D

Two options...first is easier to understand.

inquistive
Quartz | Level 8

@Reeza,

Thank you, Reeza!

It works fine. I am curious if there is any way we can get rid of this naughty 'NOT' too in the code😄.

 

I mean  two (<=) means BETWEEN. Shouldn't there be some operator(s)  that does not require support of any letters ? 

 

Let's see  if any SASsy guys or people from  SAS headquarters chime in.

Thanks,

sbxkoenk
SAS Super FREQ

See how base SAS translates NOT BETWEEN :

 

5    data want;
6     set sashelp.class;
7     where height NOT between 60 and 100;
8    run;

NOTE: There were 7 observations read from the data set SASHELP.CLASS.
      WHERE  not (height>=60 and height<=100);
NOTE: The data set WORK.WANT has 7 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds

Koen

inquistive
Quartz | Level 8
Yup, that's what every SAS user uses & knows of .

Reeza
Super User

@inquistive wrote:

 

I mean  two (<=) means BETWEEN. Shouldn't there be some operator(s)  that does not require support of any letters ? 

 

Let's see  if any SASsy guys or people from  SAS headquarters chime in.

Thanks,


So instead of the word NOT you want a symbol?

There are a few but tilde is the simplest one, it depends on your OS. 

∘ ¬ ~

Something like:

 1          OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 68         
 69         data want;
 70         set sashelp.class;
 71         
 72         where ~( 12 < age <14);
 73         run;
 
 NOTE: There were 16 observations read from the data set SASHELP.CLASS.
       WHERE  not (age>12 and age<14);
 NOTE: The data set WORK.WANT has 16 observations and 5 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       user cpu time       0.01 seconds
       system cpu time     0.00 seconds
       memory              704.37k
       OS Memory           25764.00k
       Timestamp           08/05/2022 07:19:12 PM
       Step Count                        24  Switch Count  2
       Page Faults                       0
       Page Reclaims                     226
       Page Swaps                        0
       Voluntary Context Switches        10
       Involuntary Context Switches      0
       Block Input Operations            0
       Block Output Operations           264

 

Logical Operators

Symbol/Mnemonic

Description

Example

& or AND

If both of the quantities linked by an AND are 1 (true), then the result of the AND operation is 1. Otherwise, the result is 0.

(a>b & c>d)

| or OR1

If either of the quantities linked by an OR is 1 (true), then the result of the OR operation is 1 (true). Otherwise, the OR operation produces a 0.

(a>b or c>d)

! or OR

 

 

¦ or OR

 

 

¬ or NOT2

 

not(a>b)

∘ or NOT

 

 

~ or NOT

 

 

1 The symbol that you use for OR depends on your operating environment.
2 The symbol that you use for NOT depends on your operating environment.
PaigeMiller
Diamond | Level 26

I am curious if there is any way we can get rid of this naughty 'NOT' too in the code

 

The language is set up to do certain things in certain ways. Why do you want to avoid the designed way to do things? Why is having NOT in your code even an issue? (And others have shown methods of doing this without using NOT)

--
Paige Miller
Kurt_Bremser
Super User

Be happy that you can use words. Special characters are often not available on different platforms; the 26 characters are always there, and never cause unexpected issues. Just see what happens when you use <> in SAS instead of "ne".

mkeintz
PROC Star

@Reeza wrote:
NOT ('01AUG2022'D <= birthdate <= '05AUG2022'D)

birthdate < '01AUG2022'D & birthdate >'05AUG2022'D

Two options...first is easier to understand.


I hope option 2 should be "OR", not "&"

birthdate < '01AUG2022'D OR birthdate >'05AUG2022'D

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Tom
Super User Tom
Super User

You could also let SAS tell you how it translates it.

2568  data test;
2569    set sashelp.class;
2570    where not (13 <= age <= 14) ;
2571  run;

NOTE: There were 12 observations read from the data set SASHELP.CLASS.
      WHERE  not (age>=13 and age<=14);
NOTE: The data set WORK.TEST has 12 observations and 5 variables.

So if you apply De Morgan's Law you get one of these:

WHERE not (age>=13) or not (age<=14);
WHERE (age<13) or (age>14);
Reeza
Super User

Probably, which is why the NOT is much easier 😄

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 10 replies
  • 2442 views
  • 10 likes
  • 7 in conversation