sorry that I can't explain why there is no blank in [pre] %put }}%gen( prefix=ABC, to=1 ){{; [/pre] and there is that one blank in [pre] %put }}%gen( prefix=ABC, to=3 ){{;[/pre] Should you really need to eliminate those blank separators, then wrap &prefix&i with %do ; and %end ;
If for some reason, I needed to load a macro variable for multiple values of a variable in a data step, I would use call execute() inside that loop. For example a list of the boys names in the sashelp class data set to be stored in &mStudents[pre]data _null_ ;
    call execute( '%nrstr( %%let mStudents =  )' ) ;
    do while( not EOF ) ;
       set sashelp.class( where=( sex='M' )) end= EOF ;
       call execute(  name ) ;
    end ;
    call execute( ';' ) ;
    stop ;
 run; [/pre] The generated code should be single %let statement with a separate line for each iteration of the DO While loop. 
Generally I choose the simpler solution driven normally by the context or source of the information. For collecting names into a macro variable, I would be choosing proc sql. Not sure when I would choose that data step method, but must have needed it some time.
 
Good luck
PeterC