BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
David_Billa
Rhodochrosite | Level 12

What is the meaning of <> in the below? Is it not equals or max? 

 

Whether this symbol <> has different meaning in where clause and if clause?

 

data work.REQ3;
length PrimaryBOM $50;  
set work.REQS;
if BOMQTY <> . then
do;
PrimaryBOM=cat('. .', Component);
PRIMBOMCL=Component;
end;
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

@David_Billa wrote:
I just want to know the meaning of this line in if clause,

if variable <> . then ....

If the value that results from finding the maximum of the value of VARIABLE and a missing value is TRUE then execute ....

A missing value is always less than any actual number.  So if VARIABLE is numeric then the expression

(variable <> .)

Reduces to 

(variable)

A number is TRUE if it is not zero and not missing.

 

So you are running:

if (not missing(variable)) and (variable ne 0) then ...

Which is different then just running 

if (variable ne .) then ...

(which someone might have thought there were doing by using that strange <> symbol).

 

The bottom line is never use <> as an operator.

 

Use something that is clearer to humans.

if a ne b then ...
if not (a = b) then ...
if a = b then; else ...

View solution in original post

13 REPLIES 13
data_null__
Jade | Level 19

This log should be telling you.

 

45         data _null_;
46            x = 1 <> 2;
NOTE: The "<>" operator is interpreted as "MAX".
47            y = 1 max 2;
48            if 1 <> 2 then put '*';
NOTE: The "<>" operator is interpreted as "MAX".
49            put _all_;
50            run;

*
x=2 y=2 _ERROR_=0 _N_=1
Patrick
Opal | Level 21

SAS operators are documented here

Never seen <> used this way meaning max.  ...and given its much more common meaning of Not equal to in SQL I'd never use it in my code.

David_Billa
Rhodochrosite | Level 12
It would be treated as Max or not equal to in the posted code?
PaigeMiller
Diamond | Level 26

In IF statements, <> is MAX

In WHERE statements or WHERE clauses, <> is not equal to.

--
Paige Miller
David_Billa
Rhodochrosite | Level 12
I just want to know the meaning of this line in if clause,

if variable <> . then ....
Tom
Super User Tom
Super User

@David_Billa wrote:
I just want to know the meaning of this line in if clause,

if variable <> . then ....

If the value that results from finding the maximum of the value of VARIABLE and a missing value is TRUE then execute ....

A missing value is always less than any actual number.  So if VARIABLE is numeric then the expression

(variable <> .)

Reduces to 

(variable)

A number is TRUE if it is not zero and not missing.

 

So you are running:

if (not missing(variable)) and (variable ne 0) then ...

Which is different then just running 

if (variable ne .) then ...

(which someone might have thought there were doing by using that strange <> symbol).

 

The bottom line is never use <> as an operator.

 

Use something that is clearer to humans.

if a ne b then ...
if not (a = b) then ...
if a = b then; else ...
David_Billa
Rhodochrosite | Level 12
Number will be true when it is not equal to missing. In this case, <> means
still not equals although it should be read as MAX
PaigeMiller
Diamond | Level 26

@David_Billa wrote:
Number will be true when it is not equal to missing. In this case, <> means
still not equals although it should be read as MAX

 

In an IF statement <> means maximum, it does not mean "not equal to". Boolean expression will be true when the max is not [0 or missing]. Any other maximum value (such as 7 or –2.5) is true.

 

data a;
    do y=-3 to 3 by 1, . ;
        maximum_value = y<>.;
        if maximum_value then flag=1;
        else flag=0;
        if y<>. then another_flag=1;
        else another_flag=0;
        output;
    end;
run;

 

--
Paige Miller
Tom
Super User Tom
Super User

@David_Billa wrote:
Number will be true when it is not equal to missing. In this case, <> means
still not equals although it should be read as MAX

No.  

If VARIABLE is zero then it is larger than missing but it will be FALSE since zero is FALSE.

So MAX(VARAIBLE,.) is not the same thing as (VARIABLE ne .).

 

PaigeMiller
Diamond | Level 26

@David_Billa wrote:
I just want to know the meaning of this line in if clause,

if variable <> . then ....

 

The phrase variable <> . is a Boolean expression, it is either true or false. It is taking the maximum of the value of VARIABLE and a missing value, and if that maximum value is not equal to zero (which it probably isn't), then the Boolean value is true (that's how Booleans work, 0 is false and anything else is true) and the THEN clause executes.

 

 

--
Paige Miller
PaigeMiller
Diamond | Level 26

<> is max as stated above, except that in a WHERE clause it means "not equal to"

--
Paige Miller
Tom
Super User Tom
Super User

Just do not use <> or >< as operators and you will avoid confusion.

It is not at all obvious to me why anyone would think that <> is a useful way to express not equal or maximum for that matter.

Just like elevator door open/close buttons.

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
  • 13 replies
  • 921 views
  • 8 likes
  • 6 in conversation