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;
@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 ...
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
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.
In IF statements, <> is MAX
In WHERE statements or WHERE clauses, <> is not equal to.
@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 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;
@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 .).
@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.
<> is max as stated above, except that in a WHERE clause it means "not equal to"
If that condition was meant to mean "bomqty is not missing", then you should use the "ne" mnemonic for the not equals operator.
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.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.
Ready to level-up your skills? Choose your own adventure.