BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JohnT
Quartz | Level 8

Hi,

A colleague of mine tried to do something relatively trivial, wanted to look for all values which were not null.

He used <>.

I generally never use that, I would use ^= for numbers and ne for string comparisons.

Just for fun, I ran the following:

15        
16         data not_equal;
17            a = 0; b = .;
18        
19            ne1 = ifc(a ^= b, 'Good', 'Bad ');
20            ne2 = ifc(a ne b, 'Good', 'Bad ');
21            ne3 = ifc(a <> b, 'Good', 'Bad ');
NOTE: The "<>" operator is interpreted as "MAX".
22         run;

NOTE: The data set WORK.NOT_EQUAL has 1 observations and 5 variables.

^^

The output was as follows:

a b ne1 ne2 ne3

0  Good Good Bad

I found the following:

http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000780367.htm

^^

I'm not sure how to explain why they shouldn't be using the <> syntax.

Would it be correct to say that the <> notation means MAX ?  I don't think that's quite right when I don't use brackets around a<>b.

Thanks.

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

It's not that you shouldn't use the MAX operator ... it's just that the results you get are different.  After all, just look at the results you got, where NE3 was Bad, but the others were Good.

The first two comparisons (calculating NE1 and NE2) return a 0 (when the comparison is false) or a 1 (when the comparison is true).  SAS interprets 0 as false, and 1 as true.

The third comparison ... well it isn't a comparison at all.  MAX returns the larger number, in this case 0.  As before, 0 is false.  Perhaps your colleague would be persuaded if you were to run the exact same program but with one small change.  Use:

a = 1;

Now NE3 will switch from Bad to Good.  Technically, you could even use:

a = -5;

The result will still be Good.  SAS interprets more than 0 and 1 ... it interprets 0 and missing as false, and anything else as true.  So you could also play with a combination like this:

a = .A;

b = .;

There are times when MAX is the right tool for the job.  This isn't one of them.

View solution in original post

1 REPLY 1
Astounding
PROC Star

It's not that you shouldn't use the MAX operator ... it's just that the results you get are different.  After all, just look at the results you got, where NE3 was Bad, but the others were Good.

The first two comparisons (calculating NE1 and NE2) return a 0 (when the comparison is false) or a 1 (when the comparison is true).  SAS interprets 0 as false, and 1 as true.

The third comparison ... well it isn't a comparison at all.  MAX returns the larger number, in this case 0.  As before, 0 is false.  Perhaps your colleague would be persuaded if you were to run the exact same program but with one small change.  Use:

a = 1;

Now NE3 will switch from Bad to Good.  Technically, you could even use:

a = -5;

The result will still be Good.  SAS interprets more than 0 and 1 ... it interprets 0 and missing as false, and anything else as true.  So you could also play with a combination like this:

a = .A;

b = .;

There are times when MAX is the right tool for the job.  This isn't one of them.

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
  • 1 reply
  • 4898 views
  • 0 likes
  • 2 in conversation