01-20-2017 09:32 PM
I have code like this:
%let coef = -177 1 -27 -34 -26 -27 -31 -25 -54 -28 -28 -25 -36 -36 7 8 11 50 -9 10 27;
score= %scan(&coef,1)*col1 + %scan(&coef,2)*col2 + %scan(&coef,3)*col3;
I want to calc score= -117*col1 + 1*col2 + (-27)*col3;
but i realize that %scan ignored the negative signs, so what i actually got is score= 117*col1 + 1*col2 + (27)*col3.
Can anyone help me resolve this?
01-20-2017 10:19 PM
A better method, use a temporary array to store the elements and then a loop.
You have not specified a separator for your terms in the SCAN function. Specify the delimiter/separator. When you create the macro variable list you can specify the delimiter of choice.
Also, is there a reason for using %scan instead of scan?
01-20-2017 10:38 PM
To elaborate on one point within Reeza's answer, %SCAN lets you specify blanks only as delimiters in this fashion:
Occasionally, you will see a version that is wrong, but usually works properly:
%scan(&coef,1, ' ')
While this does treat blanks as delimiters, it also treats quotes as delimiters. Usually that doesn't cause any harm, but that probably was not the intention of the programmer.