Google SAS Search

Add to Google

Thursday, March 22, 2007

Not Equal

A long long time ago (or what seems like a long time ago!), before I could could call myself a professional SAS programmer I made lots of little mistakes in my programs. Now that I have been programming for a long time and have lots of good habits, I generally tend to avoid the little mistakes. Now when I make a mistake it is generally one of the bigger varieties. :)

One of the little mistakes I remember making was using the wrong "not equal" operator. It was terribly embarrassing for me at the time, and for some reason it stuck in my memory more than the other myriad mistakes I made.

When I first got hired as a SAS programmer, I did not have a whole lot of SAS experience. I had coded quite a bit growing up, but had only used SAS in a limited function at Texas A&M Univ on Windows. In my interview I explained my SAS skills honestly, and lo-and-behold they hired me! I was hired as an "intern" and had a few months to prove myself. I was told they needed people with PC experience because most of the programmers came from a mainframe MVS TSO background (which meant nothing to me at the time) and there were going to be more PC SAS contracts coming. Well, the PC SAS contracts never appeared and I suddenly found myself knee-deep in MVS TSO and mainframe SAS. JCL, ISPF, pf8 forward, pf7 back, pf3 end-- all new to me. It was all terribly daunting and every day I came to work, I thought someone was going to ask me to leave. So I did my best to keep my head above water and learn everything as quickly as I could. I thought I was doing a pretty good job masquerading as a true-blue mainframe developer until I wrote one of my first full programs and had another programmer look at it (the first week or two was spent making small changes to other people's programs and going through logs, etc). The reviewer wanted to know what this line meant:

if x <> y then delete;

I answered "if x not equal y then delete the row." The mainframer shrugged and gave me the benefit of the doubt that I knew what I was talking about. That was until someone else (one of the programmers employed by our client-- GULP!) looked at it and pointed out in a friendly email to everyone that <> is "not equal" in BASIC, but means something entirely different in SAS. I could feel everyone looking at me differently and hear their whispers.

"Basic? Basic? Is this kid a joke?" I had been exposed as a commodore 64 hack!

Well, luckily I wasn't fired and ended up learning a tremendous amount from those mainframe SAS programmers at my first real consulting job. I truly owe them my career.

So, what does <> mean in SAS? It is the MAX operator and returns the maximum of the two values on either side of it. Conversely >< is the MIN operator and returns the smaller of the two values.

Oh wait! We're talking about SAS here, right? Then I should say <> is _usually_ the max operator, but in one situation, it can stand in as the "not equals" operator I was intending it to be.

Proc SQL of course!


  1. It's a pain in the butt as far as I am concerned. '<>' should be a not equal since that is what is understood by almost everyone but there you go...

    Legacy SAS stuff that will bite you every time. I stick with NE since it si more readable.

    Being a C# code hacker nowadays, the SAS stuff I have to refocus my mind and get back into a legacy mode whenever I hack up SAS code.

    The ISPF stuff brought back memories.


  2. I always try to use ne instead of <>.
    Add in working with SQL Server and R Code and you have the additional worries of != for ne, and <- for = (not to mention the == operator)

    More fun than Sudoku....

  3. I've just encountered something similar in an ex-colleague's code who I think used <> in a datastep believing it meant not equal.

    Using the code in your example:
    if x <> y then delete;

    If for example x=10 and y=20, does the statement become:
    if 20 then delete; ?

    What does this mean? Could someone please expand? They don't cover this in the base programmers exam!



  4. Hi,
    Can u give me some more tips for SAS programming. I am fresher and currently i am working on SAS programs, So can u guide me?

  5. Not all operators are comparison operators. The <> (MAX) and >< (MIN) operators are one such example. The NOT, AND, OR, and || (concatenation) operators are other examples of non-comparison operators. All of them can be categorized, however, as "infix" operators--that is, they apply to the operands on either side of it.

  6. Nice post you got here. I'd like to read a bit more concerning that topic. Thanx for posting that material.
    Sexy Lady
    Girls for companionship in London

  7. Its Pleasure to undergo your weblog.The above content material articles may be very outstanding, and I genuinely enjoyed reading your weblog and factors which you expressed. I take pleasure in to seem back on the standard basis,publish way more about the topic.Thanks for sharing¡­keep writing!!!