Another way to conditionally generate code is to write it to a temporary file which you then %include. Following your example above:

filename tempcode temp;

data _null_;
set SASHELP.CARS;
by MAKE;
if first.MAKE then
do;
file tempcode;
put 'title "' make 'models"; '
/ 'proc print noobs data=sashelp.cars; '
/ ' where make="' make '"; '
/ ' var make model type; '
/ 'run; '
;
end;
run;

%include tempcode / source2;
filename tempcode clear;

Which method to use depends on what you want to do and what you're most comfortable with. With the included file method, you don't have to use the trim function and the concatenate operator, and the template code inside the data step looks more like the final generated code and so might be easier to follow. There are other times when CALL EXECUTE might be easier to write or to understand. Both methods are good to know.