If it is running infinitely and not ever stopping that means that the right side of this statement:
%do %while ("%scan(%nrbquote(&&&type),&i,'*')" ne ' ');
is never being met ... the NE ' '. Not having seen your data, whatever &&&type resolves to be is not ever returning an actual value. I think the reason is that what is in the ( ) is not actually resolving due to the double quotes around the %scan() function. So it is seeing the text "%scan(%nrbquote(&&&type),&i,'*')" as not equal to '' and never ending the loop.
Try removing the double quotes in both places and see if that makes a difference. If you need the value quoted, you can try adding:
%let myval = "%scan(%nrbquote(&&&type),&i,'*';
after the do while and then use "&myval" in your index() function instead of running the %scan again.
Daniel