The IF statements are not "within" BY statements.
The first IF statement is taking advantage of the fact that when using a BY statement SAS will create flag variables that will indicate if the current observation is the first or last in the current BY group. So it resets the counter variable the data step is creating to zero when a new group starts.
Your guess on the second IF statement is going to be better than mine. Especially since it is referencing a macro variable, SUP_MAX, that you have not defined anywhere. (Programming hint: Do not use "magic" macro variables in macro code. That is a macro variable that is suddenly used by the macro but has never been defined by the macro and is not an input parameter of the macro. At the very least add a comment at the top of the macro stating that the macro will be using this externally defined macro variable.)