![The MOD function and negative values](https://blogs.sas.com/content/iml/files/2012/08/t_mod.png)
When I studied math in school, I learned that the expression a (mod n) is always an integer between 0 and q – 1 for integer values of a and q. It's a nice convention, but SAS and many other computer languages allow the result to be negative if a (or q) is