You're almost there.
proc sql;
select name into :namelist separated by ' '
from ... (as you have above)
;
quit;
That generates a macro variable, &namelist
, that has all of the name
s in one list separated by space. You can then use it however you wish. You can alter the separated by character (s) of course, and you can select complex expressions (ie, instead of select name
, you can say select cats('%mymacro(mvar=',name,')')
or similar.
I recommend trying to do the latter - constructing a macro that will do whatever it is you want done multiple times, then using this method to construct calls to that macro. It's usually easier than macro looping over a list of names.