DATA Step, Macro, Functions and more

Difference between = and eq

Reply
N/A
Posts: 0

Difference between = and eq

I learned long ago that it is better to use 'eq' when making comparisons and to use the = sign when setting the value of a variable. As in

if x eq 0 then y = 1;

I have always done it this way, but I do not remember why. So today I was trying to fix a colleague's program which seemed logically correct on the surface, but the output was clearly wrong. Eventually I tried changing all his mathematical symbols to the letter equivilent (eq, gt, ....) and the program works correctly now. But I don't know how to explain WHY it should be this way (to a guy whose first language is not english but who makes his own electronic equipment for his guitar).
Super User
Posts: 5,257

Re: Difference between = and eq

The eq operator can only be used in comparisons, in IF and WHERE for example. The = operator can be used both in comparisons and in assignments.

Some people think it's easier to read the code if using different operators in assignment and comparison statements, but technically, there is no difference.

/Linus
Data never sleeps
Ask a Question
Discussion stats
  • 1 reply
  • 2098 views
  • 0 likes
  • 2 in conversation